raulraja
01/11/2018, 3:21 PMbind()
can be flagged to be async.
IO.monad().binding {
val file = getFile("/tmp/file.txt").bind()
val lines = file.readLines().bind()
val average =
if (lines.isEmpty()) {
0
} else {
val count = lines.map { it.length }.foldLeft(0) { acc, lineLength -> acc + lineLength }
count / lines.length
}
yields(average)
}
.ev()
.attempt()
.unsafeRunAsync()
http://arrow-kt.io/docs/effects/io/
http://arrow-kt.io/docs/effects/async/
@pakoito worked on all the effects and async stuff and knows more about Rx than I do but if the question is if you can do async jumps in imperative style with coroutines without flatMap chains (rx) or callbacks (old school) I think it can be done with suspended continuations and still suspend and capture side effects.