Functors are types that can be mapped over.
Two laws (https://wiki.haskell.org/Functor#Functor_Laws):
- mapping an identity function over a functor would return the same functor
- mapping function
g
thenf
is equivalent to mapping the composed function (f ∘ g)
fmap
is a mapping function that operates on functors. It can be defined for
specific objects so that the provided mapping function can be applied in the
container. For example, fmap(f, M)
, where M is a monad, a wrapped value of
something, is used to apply funciton f
over the monad value and returns a
monad result. That is, it should return M(f(M.value))
.
Intro about functors https://medium.com/@dtinth/what-is-a-functor-dcf510b098b6
Lot's of pictures http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html#monads
Haskell tutorial http://learnyouahaskell.com/functors-applicative-functors-and-monoids
In Julia, the feature of callable structs are sometimes called functors, as mentioned in the language manual section function like objects.
Likewise, in C++, a functor is just a data type that behaves like a function. See tutorial at https://www.geeksforgeeks.org/functors-in-cpp/.
While these are also called functors, they are not the same as functors as presceibed in funcitonal programming literature and Haskell language.