So, What are Functors? (JavaScript)
“Functors” are the containers or type that can be used with “map” function.
Container.prototype.map = (f) => {
return Container.of(f(this.$value));
};
Container.of(2).map(two => two + 2);
[1, 2, 3].map((num) => num + 2);
Just what is a Functor, really? (Haskell)
Functor is “typeclass” (A lot of people coming from OOP get confused by typeclasses because they think they are like classes in object oriented languages).
A Functor is any data type that defines how “fmap” applies to it. Here’s how “fmap” works:
class Functor f where
fmap :: (a -> b) -> f a -> f b
> fmap (+3) (Just 2)
-- Just 5