liveBook · Manning

Covariant functor

As explained in Fabulous Adventures in Data Structures and Algorithms

A covariant functor maps objects between categories and maps morphisms in the same direction while preserving their structure.

A covariant functor maps objects from one category to another and preserves morphisms in the same direction. If an arrow connects A to B, the mapped objects F(A) and F(B) retain a corresponding arrow from F(A) to F(B). section 7.1

Mapping objects and arrows

Take the objects 0, 1, and 2, with arrows 0→1 and 0→2. The function F maps them to Bob, Bruce, and Eric: F(0) = Bob, F(1) = Bruce, and F(2) = Eric. The original arrows are preserved as Bob→Bruce and Bob→Eric. section 7.1

Figure 7.1 A small category with three objects, represented by the nodes, and six morphisms, represented by the arrows

Use the small category diagram to inspect objects as nodes and morphisms as arrows before following their covariant mapping. section 7.1

The same idea supports several useful distinctions:

  • A functor may map between different categories or remain within one category; the latter is a covariant endofunctor. section 7.1
  • A contravariant functor preserves morphisms while reversing their direction. section 7.4
  • In programming-language type systems, generic interfaces can be understood as covariant or contravariant functors over assignment-compatibility relationships. section 7.4

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Defines object and morphism mapping, gives a small example, and stops short of deeper category-theory development.
Examples
Uses a three-element family and arrows such as 0→1 mapping to Bob→Bruce.
What it assumes
Defines categories and morphisms before applying the covariant functor concept.
What you can do after
Understand morphism-preserving mappings and recognize their relationship to type-system variance.
How it connects
Links categories, morphisms, contravariant functors, endofunctors, and generic interfaces.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.