O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required