Scala Functor

Functional Programmingtoday !

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

You might have heard aboutMonad,Monoid,Applicative, etc…

In this episode, we are focusing on theFunctor.

The formal definition for aFunctoris a transformation from a categoryAto a categoryB. Such transformations are often represented by an arrow:A -> B.

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

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

  • All element ofAmust have a result inB
  • Identity:
    • If we defineid, the identity method:id(a) == a,
    • thenid(F) == F.map(id).
  • Composition:
    • If we definefandg, two methods,
    • thenF.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