Created
February 1, 2016 16:02
-
-
Save matsu-chara/d8b6898f57bae3740a62 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
def cont1(request: Int): Cont[Unit, Int] = | |
Cont((f: Int => Unit) => { | |
println("add 1") | |
f(request + 1) | |
println("added 1") | |
}) | |
def cont2(request: Int): Cont[Unit, Int] = | |
Cont((f: Int => Unit) => { | |
println("add 2") | |
f(request + 2) | |
println("added 2") | |
}) | |
def cont3(request: Int): Cont[Unit, Int] = | |
Cont((f: Int => Unit) => { | |
println("add 3") | |
f(request + 3) | |
println("added 3") | |
}) | |
val cont = for { | |
a <- cont1(0) | |
b <- cont2(a) | |
c <- cont3(b) | |
} yield c | |
cont.run(x => println(x)) | |
/* | |
add 1 | |
add 2 | |
add 3 | |
6 | |
added 3 | |
added 2 | |
added 1 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment