Created
October 7, 2016 14:44
-
-
Save kwijibo/70fe0a8ba7c54e09932456ae6b65508d to your computer and use it in GitHub Desktop.
Simple Task implementation
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
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