Question: If I have a function with return type `E...
# arrow
m
Question: If I have a function with return type
EitherT<ForIO, E, A>
and I want to run it via
parMapN
, how would I best accomplish this?
j
parMapN
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^^
s
It’s defined with
CoroutineContext
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 memory
Copy code
EitherT.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!") })
 }
}
All functions are also importable similar to the import above
If you’re working with
EitherT
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.
m
Thanks everyone! I'll give that a try. I might go ahead and bump up to
0.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?
👍 1
s
EitherT
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>>
.
IO<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.
m
Ah, that makes sense.
j
On that note: @simon.vergauwen with
IO<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?
s
Currently I’ve implemented 2 errors handlers
result
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.
Copy code
val test: IO<DomainError, String> = IO.raiseError(DomainError)

val default: IO<Nothing, String> = test.fallbackWith(IO.just("Example"))
👍 3