3 ms·
The explanation is kind of right but the code isn't. The map function needs to return a Functor<B> and flatMap takes a function A => Monad<B> and returns a Mon
by still_grokking 5y ago
The explanation is kind of right but the code isn't.
The map function needs to return a Functor<B> and flatMap takes a function A => Monad<B> and returns a Monad<B>.
That's actually not 100% correct either as those are in fact higher kinds, so it's more like you have a generic F<_> that can be a functor or a monad or whatever, and the signature for functor map actually returns a F<B>, and flatMap takes a A => F<B>, returning a F<B>.
It's quite easy to grok looking at Scala.