3 ms·
A functor has three things: 1. A type constructor 2. A "map" function 3. A "flatten" function So basically it is just a parametric type such as List<T> which
by thinkharderdev 5y ago
A functor has three things:
1. A type constructor
2. A "map" function
3. A "flatten" function
So basically it is just a parametric type such as List<T> which has a type constructor so you can get a concrete type (eg List<String>), a map function which takes a function f: A => B and and turns it into a function List<A> => List<B>, and a "flatten" function with will turn a List<List<A>> into a List<A>.
The last part is what allows "flatMap" which takes a function f: A => List<B> and turns it into a function List<A> => List<B> and is really just a shorthand for doing map and then flatten.