Easiest functor ever - Identity, it's just a wrapper over some value:
It's not a problem to wrap/unwrap this value, here we use subtyping relations for it:
Here this simple functor holds a first letter of latin alphabet. It's a covariant functor from Arrow into Arrow so that we can map over this A letter and replace it with other characters:
Alternatively, you can use a slightly modified operator if you just want to replace value ignoring input of an Arrow, i.e. factoring through Unit. This object is very important one, soon you will understand why...
This Alone functor you can not just map over it's content, but also project/inject values from/into it! I know that it may sound quite obvious, but I intentionally use the simplest example ever possible. If both operators (ryo/yor) work in such a way that they form a natural isomorphism then this type of functors is also called Representable (or Naperian in some papers):
However it's rather a rare case when functor is fully Representable, more often we have one side of such a natural isomorphism. Let's take a look on products first:
Since products are limits we can project items from them:
As in case with Alone functor we use Unit here as a representing object since an operator already focuses either on first or second parameter:
But what if we want to leave a possibility to choose? We can use another functor parameter arrangement where both of them are focused, so that we need another representing object - Sum of Units:
Alternatively we can pack some product value into Twice and focus on only one paremeter using the same representing object:
Twice functor is actually fully Representable since you can also project items into it:
In all examples above we used either Unit or Sum of Units. There is a case when we can use it's counterpart - Void:
Challenge: you can represent Stops with Unit but not with Void. Why?
Challenge: you can represent List with both Unit and Void, but Nonempty List with Unit only. Why?
Regarding Maybe functor, Unit co-represents a slot with a value inside while Void co-represents empty box. I bet you can guess what does it all mean:
So that Maybe functors co-represented by Void is 0 and by Unit is 1, neutral elements for Sum and Product. This rule applies for all lax (semi)monoidal functors, including jointed ones.
Another example of usage of representing objects is evaluation of some primitives, it works similarly to hc operator except that we get only functor's focused parameter:
So far we've only seen examples with covariant functors but there are also contravariant ones:
There is a class of functors that covariant and contravariant at the same time, depends on which paremetrs to focus - Hom functors. And we also have these aliases for representing objects as well:
If you look at type declarations above you will notice that they are actually identical!
Follow up reading: Initialising data structures