#readwise
# Functors

## Metadata
- Author: [[bartoszmilewski.com]]
- Full Title: Functors
- URL: https://bartoszmilewski.com/2015/01/20/functors/
## Highlights
- **A functor is a mapping between categories. Given two categories, C and D, a functor F maps objects in C to objects in D** — it’s a function on objects. If a is an object in C, we’ll write its image in D as F a (no parentheses). But a category is not just objects — it’s objects and morphisms that connect them. **A functor also maps morphisms — it’s a function on morphisms. But it doesn’t map morphisms willy-nilly — it preserves connections.** So if a morphism f in C connects object a to object b,
f :: a -> b
the image of f in D, F f, will connect the image of a to the image of b:
F f :: F a -> F b

- **As you can see, a functor preserves the structure of a category: what’s connected in one category will be connected in the other category.**
- **these conditions make functors much more restrictive than regular functions. Functors must preserve the structure of a category. If you picture a category as a collection of objects held together by a network of morphisms, a functor is not allowed to introduce any tears into this fabric.**
- We often say that fmap lifts a function.
- To show that the type constructor Maybe together with the function fmap form a functor, we have to prove that fmap preserves identity and composition. These are called “the functor laws,” but they simply ensure the preservation of the structure of the category.
- To get some intuition as to the role of functors in programming, we need to look at more examples. Any type that is parameterized by another type is a candidate for a functor. Generic containers are parameterized by the type of the elements they store