Created
October 7, 2016 02:55
-
-
Save phi16/1eb2e3ac4060b076702f70f6155a7bac to your computer and use it in GitHub Desktop.
Reader Monad
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
| function *f(){ | |
| var a = yield "Arg1"; | |
| var b = yield "Arg2"; | |
| return a+b; | |
| } | |
| function *add(g1,g2){ | |
| var x = yield* g1; | |
| var y = yield* g2; | |
| return x+y; | |
| } | |
| function *output(g){ | |
| var ret = yield* g; | |
| console.log(ret); | |
| } | |
| function exec(g){ | |
| var u; | |
| var val; | |
| while(u = g.next(val), !u.done){ | |
| if(u.value == "Arg1")val = 3; | |
| if(u.value == "Arg2")val = 5; | |
| } | |
| } | |
| exec(output(add(f(),f()))); // 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment