It just explains interface but not the purpose
# arrow
d
It just explains interface but not the purpose
p
That's one of the things that's a bit too abstract. Monad (or Functor, or Traverse) is a set of helper functions, so they're only useful in the sense that help you convert something with a shape into a something of different shape, using one transformation. For each permutation of origin, destination, and transformation there's (hopefully) a function in a typeclass
what you'll do with them depends on your context. There are hints of what to use them for (Applicative for independent computation, monad for sequential, Async for threads...), but use is up to discovery.
so the lookup in a typical FP language or lib isn't:
where's Monad
, but rather,
where's something that goes from F<A> -> (A -> F<B>) -> F<B>
and that's in JS called,
then
, in haskell as
bind
, in Kotlin's stdlib as
flatMap
, in Arch Components as
switchMap
, and in Rust is
and_then
all of them do the same, some only work for promises or option or result or list or whatever, but they all work the same
r
Monad is for sequential chains of effects. Effects are concerns: absence
Option
, ambiguous result
Either
, Async promises
Deferred
, etc… We understand that is sequential because in order to advance in the computation we need the computed value as in the
bind
or
flatMap
signature : (A) -> F<B>. You can’t obtain a new value in the context of
F<B>
until the previous
F<A>
had produced an
A
.
There is many ways to explain it
but it varies so much because not many people reach the same conclusion when understanding monads and effect in general through the same learning path.
People in FP langs like Haskell are exposed to more of these concepts because of language design and that does not make them more capable
Everyone can learn it and we are new in Kotlin doing this so we have the chance by modifying the Arrow documentation to shape how Kotlin folk understand monads based on what is useful to them as well.