> For the complete documentation index, see [llms.txt](https://mandober.gitbook.io/math-debrief/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mandober.gitbook.io/math-debrief/450-category-theory/topics/functor.md).

# Functor

<https://bartoszmilewski.com/2015/01/20/functors/>

> A **functor** is a structure-preserving mapping from one category into another. It maps objects into objects and morphisms into morphisms.

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`. But a category also contains morphisms between these objects and so a functor also maps morphisms, it's also a function on morphisms. However, it doesn't map morphisms willy-nilly - it maps them while preserving connections (it preserves structure).

If a morphism `f` in `C` connects object `a` to object `b`, we denote this by `f :: a -> b`, and the image of `f` in `D`, `F f`, will connect the image of `a` to the image of `b`, denoted by `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.

However, that' nt all, there's something more to the structure of a category; there's also *composition of morphisms*. If `h = g . f`, then we want its image under `F` to be a composition of the images of `f` and `g`, `F h = F g . F f`.

And finally, we want all *identity morphisms* in C to be mapped to identity morphisms in D, `F idᴀ = idꜰᴀ`. Here, `idᴀ` is the identity at the object `a`, and `idꜰᴀ` the identity at `F a`.

* F functor has taken `a` (in C) and mapped it into `F a` i.e. `Fa` (in D)
* obj `a`  (in C) has its identity arrow `1a`
* obj `Fa` (in D) has its identity arrow `1Fa`
* F functor has taken `1 a` (in C) and mapped it into `1 Fa` (in D)
* `1Fa == F1a`

```
     g :: (a -> b)
+  F g :: Functor f => f a -> f b
--------------------------------- all together now:
= fmap :: (a -> b)  -> f a -> f b
```

The conditions a transformation must fullfilled to be a **functor**:

* it must map objects (in C) to objects (in D)&#x20;

  `a ⟼ F a`
* it must map arrows (in C) to arrows (in D)&#x20;

  `f ⟼ F f`
* it must map composition of arrows (in C) to composition of arrows (in D)&#x20;

  `g . f ⟼ F g . F f`
* it must map identity arrows (in C) to identity arrows (in D)&#x20;

  `1a ⟼ F 1a == 1 Fa`

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. It may smash objects together, it may glue multiple morphisms into one, but it may never break things apart.

This no-tearing constraint is similar to the continuity condition you might know from calculus. In this sense functors are "continuous" (although there exists an even more restrictive notion of continuity for functors).

Just like functions, functors may do both collapsing (surjectivity) and embedding (injectivity). The embedding aspect is more prominent when the source category is much smaller than the target category.

In the extreme, the source can be the trivial singleton category - a category with one object and one morphism (the identity). A functor from the singleton category to any other category simply selects an arbitrary object in the latter category. This is fully analogous to the property of morphisms from singleton sets selecting elements in target sets.

> The maximally collapsing functor is called the constant functor `Δc`.

It maps every object in the source category to a selected object `c` in the target category. It also maps every morphism in the source category to the identity morphism `1c`. It acts like a black hole, compacting everything into one singularity.

...

* An isomorphism is invertible, a general functor is not. It can map multiple objects to one object and multiple morphisms to one morphism. You cannot invert such a mapping. A collapsing or an embedding mapping is not invertible.
* Any two non-empty categories can be mapped using the `Const` functor.
* A functor is a mapping of objects and morphisms. Every object and every morphism from C must be mapped. But not all objects and morphism in D have to be covered. This is similar ot functions: they need not to be strictly subjective or injective.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mandober.gitbook.io/math-debrief/450-category-theory/topics/functor.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
