Functors
In Chapter 3, Types and Type Casting, we talked a little about category theory. Here we go a little further in category theory and talk about Functors. A Functor contains morphisms such as a map function, which transforms the Functor. We can think about a Functor as a functional design pattern.
Knowing category theory is great, but we do not have to. So simply put, a Functor is a structure or container that we can map over. In other words, a Functor is any type that implements the map function. Examples of Functors are Dictionary, Array, Set, Optional, and Closure types.
A Functor applies morphisms or functions to the values it contains, instead of itself. Suppose if we call a function such as doSomething(param: Double), then it ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access