Understanding Functors

Michele Riva
openmind
Published in
5 min readApr 14, 2019

--

When you’re digging deep into a language or a paradigm, you’ll inevitably find some concepts that are hard to understand.
Not every developer have an academic background so same concepts, terms or abstractions are hard to understand and adopt.

One concept that’s certainly hard to understand is: what is a Functor?
Well, I bet you’re already using functors every day without knowing it!

A Functor is a map between two categories.

Real world example? The awesome .map method from our first article, can be applied on arrays… which are functors!

As written in the Haskell Data.Functor specification, Functors uniforms action over a parameterized type, generalizing the map function on lists.

Let’s throw away all that abstract things and let’s see in practice how to adopt Functors!

Functors in practice

As you can see in the example above, an array is functor because we can map over it.
We can apply a function to each element and get back the same structure, respecting the Functor Laws:

--

--