Skip to content

Instantly share code, notes, and snippets.

@xgrommx
xgrommx / state-example-game.js
Created June 26, 2016 21:04 — forked from hallettj/state-example-game.js
Implementation of a State monad in JavaScript
/*
* 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
@xgrommx
xgrommx / exampleUsage.js
Created June 26, 2016 21:05 — forked from jethrolarson/exampleUsage.js
AGeneric interface fantasy-land objects
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]
@xgrommx
xgrommx / SKI.js
Created July 23, 2016 01:02 — forked from Avaq/SKI.js
Combinatory Fun
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))
@xgrommx
xgrommx / fold.js
Created July 23, 2016 01:02 — forked from Avaq/fold.js
Functional JavaScript cookbook
//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;
@xgrommx
xgrommx / combinators.js
Created July 23, 2016 01:03 — forked from Avaq/combinators.js
Combinators
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)));
@xgrommx
xgrommx / Marble.js
Created August 29, 2016 01:17 — forked from gaearon/Marble.js
Marble-style sequencer + sampler for https://github.com/FormidableLabs/react-music
/*
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',
]}
@xgrommx
xgrommx / IO.sjs
Created September 6, 2016 11:33 — forked from gerardpaapu/IO.sjs
Async IO Monad for Javascript
function IO(unsafePerform) {
this.unsafePerform = unsafePerform;
}
IO.prototype.of = IO.of = function (v) {
return new IO(function (ctx, cb) {
cb(null, v);
});
};
@xgrommx
xgrommx / _delegated-component.md
Created September 15, 2016 22:31 — forked from developit/_delegated-component.md
DelegatedComponent

Experiment: Backbone-style events in Preact

What if we wanted to use backbone-style event delegation within the component paradigm afforded by react/preact/etc? Would that be useful?

Example

Basic usage:

@xgrommx
xgrommx / do.js
Created September 23, 2016 22:28 — forked from markandrus/do.js
Do-notation
// This supports more cases but removes support for if-statements.
macro $do {
// Base Cases
case {_ { $ma:expr } } => {
return #{
function() {
return $ma
}()
}
@xgrommx
xgrommx / Tree.hs
Created October 13, 2016 20:40 — forked from queertypes/Tree.hs
Traverse, Fold, Functor for Tree
{-# 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