September 2018
Intermediate to advanced
398 pages
9h 43m
English
Apply is a subclass of Functor. It declares an additional ap function. Here is a simplified definition of cats.Apply:
trait Apply[F[_]] extends Functor[F] { def ap[A, B](ff: F[A => B])(fa: F[A]): F[B] /** Alias for [[ap]]. */ @inline final def <*>[A, B](ff: F[A => B])(fa: F[A]): F[B] = ap(ff)(fa)
This signature means that for a given context F, if we have a function A => B inside of F, we can apply it to A inside of another F to obtain F[B]. We can also use ap alias operator, <*>. Let's try it out with different F contexts, as follows:
import cats.implicits._ Option[String => String]("Hello " + _).ap(Some("Apply")) // res0: Option[String] = Some(Hello Apply) Option[String => String]("Hello " + _) <*> None // res1: Option[String] ...
Read now
Unlock full access