Last active
September 4, 2017 00:10
-
-
Save huijari/ef76b1d57ba87bafe07862c0cd65bf3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
from, | |
just, | |
} from 'comea' | |
const log = label => value => console.log(label, value) | |
const range = x => from(Array(x).fill(0).map((_, k) => k + 1)) | |
const bind = (base, f) => next | |
base(data => f(data)(next)) | |
// f x == just x >>= f | |
const first = _ => { | |
const x = 3 | |
range(x)(log('first')) | |
bind(just(x), range)(log('first*')) | |
} | |
// m == m >>= just | |
const second = _ => { | |
const o = from([1, 2, 3]) | |
o(log('second')) | |
bind(o, just)(log('second*')) | |
} | |
// m >>= (x => f(x) >>= h) == m >>= f >>= h | |
const third = _ => { | |
const o = from([1, 2, 3]) | |
bind(o, x => bind(range(x), range))(log('third')) | |
bind(bind(o, range), range)(log('third*')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment