What if we wanted to use backbone-style event delegation within the component paradigm afforded by react/preact/etc? Would that be useful?
Basic usage:
/* | |
* Example of a state monad in use. This is adapted from an example on | |
* the Haskell Wiki: | |
* http://www.haskell.org/haskellwiki/State_Monad#Complete_and_Concrete_Example_1 | |
*/ | |
require(['state', 'qunit'], function(state, qunit) { | |
/* | |
* playGame() is a recursive function that given an array of moves | |
* defines an algorithm for constructing a final game score. Along |
var Maybe = require('./maybe.js') | |
var List = require('./list.js') | |
//Pass fantasy implementations to it | |
var {concat, map} = require('fantasy')({Maybe, List}) | |
mapDouble = map(a => 2 * a) | |
mapDouble([1, 2]) | |
//[2, 4] |
const S = f => g => x => f(x)(g(x)) | |
const K = x => y => x | |
const I = S(K)(K) | |
const B = S(K(S))(K) | |
const C = S(S(K(B))(S))(K(K)) | |
const A = S(K(I)) | |
const T = C(A) | |
const W = S(S)(K(I)) |
//Combinators | |
const I = x => x; | |
//List manipulation | |
const head = xs => xs[0]; | |
const tail = xs => xs.slice(1); | |
const append = x => xs => [...xs, x]; | |
//Iteration | |
const foldl = f => y => xs => xs.length > 0 ? foldl(f)(f(y)(head(xs)))(tail(xs)) : y; |
const I = x => x; | |
const K = x => y => x; | |
const A = f => x => f(x); | |
const T = x => f => f(x); | |
const W = f => x => f(x)(x); | |
const C = f => y => x => f(x)(y); | |
const B = f => g => x => f(g(x)); | |
const S = f => g => x => f(x)(g(x)); | |
const P = f => g => x => y => f(g(x))(g(y)); | |
const Y = f => (g => g(g))(g => f(x => g(g)(x))); |
/* | |
This replaces <Sequencer> + multiple <Sampler>s with a marble diagram sequencer. | |
You can use it like this: | |
<Marble | |
resolution={16} | |
samples={[ | |
'samples/kick.wav', | |
'samples/snare.wav', | |
]} |
function IO(unsafePerform) { | |
this.unsafePerform = unsafePerform; | |
} | |
IO.prototype.of = IO.of = function (v) { | |
return new IO(function (ctx, cb) { | |
cb(null, v); | |
}); | |
}; |
// This supports more cases but removes support for if-statements. | |
macro $do { | |
// Base Cases | |
case {_ { $ma:expr } } => { | |
return #{ | |
function() { | |
return $ma | |
}() | |
} |
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE DeriveFoldable #-} | |
{-# LANGUAGE DeriveTraversable #-} | |
module Main where | |
import Prelude hiding (foldr) | |
import Control.Applicative | |
import Control.Monad (void) | |
import Data.Foldable | |
import Data.Traversable |