Srki Rakic
06/17/2020, 4:44 PMIO<Either<InvalidCommand, Command)>> as an input to a function that takes Command as a parameter and returns IO
return EitherT.monad<ForIO, DomainError>(IO.monad()).fx.monad {
val (command) = EitherT(commandFrom(commandType, commandString))
val (eventRecord) = EitherT(commandHandler.handle(command).map { it.right() })
eventRecord
}.value().fix()
.map { result -> result.fold({ Response.Error(it.toString()) }, { Response.Success(it) }) }
.unsafeRunSync()
Does this seem like the right approach?simon.vergauwen
06/17/2020, 6:39 PMsuspend and Either and achieve the same result. Arrow Fx Coroutines exposes the same API as IO over suspend, and we’re refactoring Arrow-Core to be inline and expose a suspend fx block over data types.
Either.fx {
val (command) = commandFrom(commandType, commandString)
val (eventRecord) = commandHandler.handle(command).map { it.right() }
}.fold({ Response.Error(it.toString()) }, { Response.Success(it) })
But if you’re not using the IO api like here, so you’re not using any of the Arrow Fx typeclasses such as Concurrent or Async there is no need to use IO on top of Either. Hard to see from the snippet.simon.vergauwen
06/17/2020, 6:40 PM0.11.0-SNAPSHOT for Arrow Core & Arrow Fx.simon.vergauwen
06/17/2020, 6:40 PMunsafeRunSync thoSrki Rakic
06/17/2020, 7:52 PMunsafeRunSync in the REST controller endpoint. You say what you recommended above won’t work with unsafeRunSync even if bump the version?simon.vergauwen
06/17/2020, 8:03 PMEnviroment type to expose unsafeRunSync
RIf your
If your REST controller has suport for suspend, then you can just call suspend function from there. Otherwise if you’re interested in trying the library out you could use a temporary reantrant lock to write unsafeRunSync for suspend. Or use startCoroutine from the standard library, `startCoroutineCoroutine`from the Arrow Fx Coroutines library. Both take a Continuation callback with a CoroutineContext. The library exposes similar dispatchers as Arrow Fx IO such as ComputationPool, IOPool etc
https://github.com/arrow-kt/arrow-fx/pull/169
https://github.com/arrow-kt/arrow-fx/blob/master/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Platform.kt#L128
I just noticed the docs aren’t up yet. Even though they’re written. I’ll fix that tomorrow 🙂simon.vergauwen
06/17/2020, 8:03 PMSrki Rakic
06/18/2020, 11:34 PMSrki Rakic
06/18/2020, 11:34 PM