3 ms·
probably because flatMap (also called chain) is an important array (or monads in general) function in functional programming. If anything, .flat() is the aberra
by beaconstudios 5y ago
probably because flatMap (also called chain) is an important array (or monads in general) function in functional programming. If anything, .flat() is the aberration.
- ReleaseCandidat 5y ago> If anything, .flat() is the aberration. Same as `flatmap` (`bind`), `flat` is 'part' of a monad (as `join`).
- beaconstudios 5y agogood point, I didn't think of that equivalence.
- contravariant 5y agoIn mathematics it would be 'flat' that is the important one, not flatMap. You get 'flatMap' by just composing the monad multiplication 'flat' with the monad functor's mapping of arrows 'map'. That's mainly just to highlight the similarity with regular monoids though. But in a program it usually makes sense to do the flattening in one go, since it avoids the need to do some possibly expensive intermediate calculations.
- deleted 5y ago[deleted]