Skip to content

Instantly share code, notes, and snippets.

@kwijibo
Created October 7, 2016 14:44
Show Gist options
  • Save kwijibo/70fe0a8ba7c54e09932456ae6b65508d to your computer and use it in GitHub Desktop.
Save kwijibo/70fe0a8ba7c54e09932456ae6b65508d to your computer and use it in GitHub Desktop.
Simple Task implementation
const Task = fork => ({
map: f => Task((reject, resolve)=>{ fork(reject, x => { resolve(f(x)) }) }),
chain: f => Task((reject, resolve)=>{ fork(reject, x => { f(x).fork(reject, resolve) }) }),
join: () => Task(fork).chain(i=>i),
ap: A => A.map(a => Task(fork).map(f => f(a))).join(),
fork
})
Task.of = x => Task((_,resolve)=>{ resolve(x)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment