mattmoore
02/03/2020, 7:53 PMEitherT<ForIO, E, A> and I want to run it via parMapN, how would I best accomplish this?Jannis
02/03/2020, 7:56 PMparMapN comes from concurrent so should be able to do: EitherT.concurrent(IO.concurrent()).run { parMapN(...) }
Not sure if parMapN is defined with CoroutineContext.parMapN as receiver, so try both^^simon.vergauwen
02/03/2020, 8:02 PMCoroutineContext as a receiver atm, you should also be able to import the extension function with arrow.fx.mtl.extensions.either.concurrent.parMapN if I am not mistaken but this is from memorysimon.vergauwen
02/03/2020, 8:04 PMEitherT.concurrent(IO.concurrent()).run {
/* full Concurrent API availblable here */
fx.concurrent {
val i = !just(1)
val winner = !dispatchers().default().raceN(sleep(1.seconds), effect { println("Hello World!") })
}
}simon.vergauwen
02/03/2020, 8:05 PMsimon.vergauwen
02/03/2020, 8:06 PMEitherT typed to IO you might also take a look at 0.11.0-SNAPSHOT where currently a concrete IO<E, A> is build. The functionality is finished, the API & docs are being prepared while a proper deprecation cycle will follow for the last minor release.mattmoore
02/03/2020, 8:21 PM0.11.0-SNAPSHOT as well. I like the idea of IO<E, A>
For my own understanding, I noticed IO has an attempt (From memory) that appears to convert to Either - is this another equivalent to EitherT, or any caveats?simon.vergauwen
02/03/2020, 8:24 PMEitherT is just a wrapper that allows you to create Monad instances for the types of the shape F<Either<E, A>> or Kind<F, Either<E, A>>.
The reason this is necessary is because you need to nest both flatMap calls, which don’t compose since they’re callback in nature.
If you call .value() on EitherT you obtain the nested IO<Either<E, A>>.simon.vergauwen
02/03/2020, 8:26 PMIO<E, A> will over the exact same functionality as EitherT but being concrete to IO and with a nicer concrete API and an optimised runtime.mattmoore
02/03/2020, 8:27 PMJannis
02/03/2020, 8:29 PMIO<E, A> will attempt result in IO<Nothing, Either<E, A>> or IO<E, Either<Throwable, A>>. And if it is the former, how does one handle uncaught exceptions etc?simon.vergauwen
02/03/2020, 8:33 PMresult and attempt.
attempt is what it was before IO<E, Either<Throwable, A>>.
result results in IO<Nothing, IOResult<E, A>> where IOResult is a sumtype over A, E and Throwable this could be replaced by Union later.
Other combinations can easily be implemented as will. Other things available are also fallbackWith which can also turn your E into nothing providing a pure value.
val test: IO<DomainError, String> = IO.raiseError(DomainError)
val default: IO<Nothing, String> = test.fallbackWith(IO.just("Example"))