Scala Functor

Functional Programming today !

And let’s start by the easiest one: Functor.

You might have heard about Monad, Monoid, Applicative, etc…

In this episode, we are focusing on the Functor.

The formal definition for a Functor is a transformation from a category A to a category B. Such transformations are often represented by an arrow: A -> B.

This transformation, in Scala, is translated to the method map that we have seen a lot in the past.

A Functor (F), in category theory, must follow several rules:

  • All element of A must have a result in B
  • Identity:
    • If we define id, the identity method: id(a) == a,
    • then id(F) == F.map(id).
  • Composition:
    • If we define f and g, two methods,
    • then F.map(f).map(g) == F.map( g(f(_)) ).

In the following episode, we are going to learn more about the other component of the category theory ecosystem and functional programming overall.

Reveal more information and clues
Load Exercise