September 2018
Intermediate to advanced
398 pages
9h 43m
English
Applicative is a subclass of Apply. It declares an additional function, called pure:
@typeclass trait Applicative[F[_]] extends Apply[F] { def pure[A](x: A): F[A] }
The pure function puts any value of type A into the F context. A type F that has an instance of Applicative[F] and that respects the associated laws is called an Applicative Functor.
Let's try this new pure function with different F contexts, as follows:
import cats.Applicative import cats.data.{Validated, ValidatedNel} import cats.implicits._ Applicative[Option].pure(1) // res0: Option[Int] = Some(1) 3.pure[Option] // res1: Option[Int] = Some(3) type Result[A] = ValidatedNel[Throwable, A] Applicative[Result].pure("hi pure") // res2: Result[String] = Valid(hi ...
Read now
Unlock full access