September 2018
Intermediate to advanced
398 pages
9h 43m
English
Functor is a higher-kinded type of arity one. It accepts a unary type parameter F[_]. In other words, its type parameter must be a type that has a type parameter itself; for instance, Option[A], Vector[A], Future[A], and so on. It declares a map method that can transform the elements inside of F. Here is a simplified definition of cats.Functor:
trait Functor[F[_]] { def map[A, B](fa: F[A])(f: A => B): F[B]
This should be familiar. We have already seen several classes of the SDK that define a map function doing the same thing: Vector, Option, and so on. Hence, you might wonder why you would ever need to use an instance of Functor[Option] or Functor[Vector]; they would only define a map function that is already available.
One ...
Read now
Unlock full access