Functor
A functor is a type constructor with a map operation that applies a function to the value inside a container without changing the container's structure.
Purpose
Unify mapping as an abstraction, the basis of monads, supporting in-container transformation.
Mechanism
F<T> provides map: F<T> × (T→U) → F<U>. It satisfies the identity law (map(id) = id) and the composition law (map(f∘g) = map(f)∘map(g)). List, Option, and Future are all functors. map preserves the container's structure and only transforms the inner value.
Use cases
- Functional programming
- Container abstraction
- Unified mapping