Applicative is Apply that also has point or pure methods. Scalaz defines Applicative[F[_]] trait with point abstract method.

def point[A](a: => A): F[A]

point method lifts A to F[A]. Since Applicative is Apply it inherits all the methods that Apply offers plus it needs to provide implementation for map and ap methods. Note that Applicative implements map using point and ap methods:

override def map[A, B](fa: F[A])(f: A => B): F[B] = ap(fa)(point(f))

Scalaz offers following syntax/derived functions:

  • η, point and pure. Lift value into F.
  • replicateM. Performs action n times and returns list of results.
  • replicateM_. Performs action n times and returns unit.

Since Option is Applicative I’m gonna demonstrate those methods on Optioni with short examples:

import scalaz.std.option.optionInstance
import scalaz.syntax.std.option._
import scalaz.syntax.applicative._

display(1.η, """ 1.η """)
display(1.point, """ 1.point """)
display(1.pure, """ 1.pure """)

display(1.some.replicateM(3), """ 1.some.replicateM(3) """)
display(1.some.replicateM_(3), """ 1.some.replicateM_(3) """)

Output

1.η                                                        Some(1)
1.point                                                    Some(1)
1.pure                                                     Some(1)
1.some.replicateM(3)                                       Some(List(1, 1, 1))
1.some.replicateM_(3)                                      Some(())