Skip to content

Instantly share code, notes, and snippets.

@huijari
Last active September 4, 2017 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huijari/ef76b1d57ba87bafe07862c0cd65bf3b to your computer and use it in GitHub Desktop.
Save huijari/ef76b1d57ba87bafe07862c0cd65bf3b to your computer and use it in GitHub Desktop.
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