Functor

A functor is a type that can be mapped over: given a function and a value wrapped in some container, mapping applies the function to the contents and returns a new container of the same shape. The Haskell wiki defines the Functor type class as representing “the mathematical functor: a mapping between categories in the context of category theory,” and notes that “in practice a functor represents a type that can be mapped over.”

In Haskell this mapping is the operation fmap, with the type signature fmap :: (a -> b) -> f a -> f b. The same source describes the infix operator (<$>) as a synonym for fmap. Common examples are lists, optional values, and futures: in each case mapping transforms the inner values without changing the outer structure, so a list stays the same length and an empty optional stays empty.

Functors are the simplest member of a hierarchy of related abstractions borrowed from category theory that runs functor, applicative, and monad, each adding more power. The Haskell wiki spells out the functor laws, requiring that mapping the identity function changes nothing and that mapping a composition of functions equals mapping each in turn, which is what guarantees structure is preserved.