/ scala

TOTD: Scala - Functors

Let's talk about Functors. Functors are structure-preserving maps between two algebraic structures. What that means is that a structure that can map into another structure [of the same shape] is considered a functor. The law here is that the structure must maintain the same "shape". This is called a homomorphism. A popular example for functors are lists. Lists are mappable. e.g. List(1, 2, 3).map(_*3) Notice that the result is still a List[A], keeping the same shape. Another popular example is Some(3).map(_.toString). Notice the Option keeps the same shape, as Option[A].