pakoito
02/26/2019, 3:55 PMstreetsofboston
02/26/2019, 3:56 PMdelay(...)
call between two bind()-calls and it will happen.pakoito
02/26/2019, 3:56 PMpakoito
02/26/2019, 3:56 PMstreetsofboston
02/26/2019, 3:57 PMstreetsofboston
02/26/2019, 4:07 PMraulraja
02/26/2019, 5:14 PMraulraja
02/26/2019, 5:36 PMeffect
is not a valid combinator on Eitherraulraja
02/26/2019, 5:36 PMraulraja
02/26/2019, 5:36 PMraulraja
02/26/2019, 5:36 PMfx
from Either for this programraulraja
02/26/2019, 5:37 PMMonadDefer
.raulraja
02/26/2019, 5:38 PMeffect
will never be available for the Either fx
block, only for monad defer.raulraja
02/26/2019, 5:38 PMraulraja
02/26/2019, 5:38 PMpackage arrow.effects.zio
import arrow.core.Either
import arrow.core.extensions.either.applicative.just
import arrow.core.extensions.either.applicative.map
import <http://arrow.effects.IO|arrow.effects.IO>
import arrow.effects.extensions.io.fx.fx
import arrow.effects.extensions.io.unsafeRun.runBlocking
import arrow.unsafe
import kotlinx.coroutines.delay
suspend fun getValue1(): Either<Throwable, Int> {
delay(100) // <-- Either can't suspend anything because it's an eager data type, so you can't use the `either fx`
return 5.just()
}
suspend fun getValue2(): Either<Throwable, Int> {
return 10.just()
}
val program: IO<Either<Throwable, Int>> =
fx {
val v1 = !effect { getValue1() }
val v2 = !effect { getValue2() }
val result = map(v1, v2) { it.a + it.b }
!effect { println(result) }
result
}
fun main() {
unsafe { runBlocking { program } } //Right(b=15)
}
streetsofboston
02/26/2019, 5:42 PMstreetsofboston
02/26/2019, 5:44 PMval result = map(v1, v2) { it.a + it.b }
is not necessary and val result = !v1 + !v2
is possible, for example?raulraja
02/26/2019, 5:47 PMraulraja
02/26/2019, 5:51 PMstreetsofboston
02/26/2019, 6:16 PMkartoffelsup
02/26/2019, 6:54 PMeffect
from MonadSyntax, since BindSyntax defines it and FunctorSyntax derives from BindSyntax. Or am I missing something? 🙁 Would've loved to help out but that's a bit too complex for me 😢raulraja
02/27/2019, 4:53 PMraulraja
02/27/2019, 4:53 PMraulraja
02/27/2019, 4:54 PMraulraja
02/27/2019, 4:54 PM