Bruno
01/28/2020, 9:27 AMfun add(a: Int, b: Int): Int = a + b
suspend fun main1(args: Array<String>) =
IO.fx {
val sc = Scanner(System.`in`)
val nextInt = effect { sc.nextInt() }
val added = IO.applicative()
.map(nextInt, nextInt) { (a, b) -> add(a, b) }.bind()
effect { println(added) }.bind()
}.run { suspended() }
pakoito
01/28/2020, 11:12 AMIO
operations to run them.
The examples we have that look like this are mostly the Free Monad ones, which is just an implementation detail.Bruno
01/28/2020, 1:10 PMsealed class IoOperations {
object ReadConsole : IoOperations()
object PrintConsole : IoOperations()
}
pakoito
01/28/2020, 1:21 PMpakoito
01/28/2020, 1:21 PMpakoito
01/28/2020, 1:21 PMpakoito
01/28/2020, 1:21 PMsealed class IoOperations<T> {
object ReadConsole : IoOperations<Unit>()
object PrintConsole : IoOperations<Unit>()
}
PhBastiani
01/28/2020, 2:10 PM