|
|
|
|
|
by chriswarbo
357 days ago
|
|
> a “map” operation that unwraps a monad value, applies a function to it, and wraps the result It can be misleading to think of "unwrapping" a monadic value, since the monad interface does not support it. For example, there's no way to implement a function `List<T> -> T` using monad operations; it requires something entirely separate (e.g. indexing into a List, in this case). What monads do provide is `join`, which turns nested monadic values into flat ones, like `List<List<T>> -> List<T>`. Even this seemingly trivial example is interesting though, since there are many ways to "flatten" a List<List<T>> into a List<T>: we could concatenate (e.g. depth-first), interleave (e.g. breadth-first), diagonalise (to support infinite lists), operate on chunks at a time (e.g. iterative deepening), etc. |
|
this is called catamorphism, that is folding. The opposite transformation is called anamorphism, that is generation from a seed value.