simon.vergauwen
02/23/2020, 9:52 AMEither
it’s easier to just use Either.fx
. In case you want to write polymorphic code using the typeclasses, it requires a slightly different syntax. Since depending on which typeclass you use, Monad
, MonadThrow
, Async
, Concurrent
etc you get a more or less powerful DSL enabled.
Either.monad<Exception>().fx.monad {
!mapN(fa, fb) { a, b -> a + b }
}
IO.concurrent().fx.concurrent {
// Concurrent & parallel DSL
!parMapN(fa, fb) { a, b -> a + b }
}
Since we already know what the most powerful powers are for Either
or IO
we can already hide that additional boilerplate for you.
We achieve these different powers by using different receivers in the DSL. MonadSyntax
for Either
& ConcurrentSyntax
for IO
in this example.