Applicative

trait Applicative[F[_]]

A functor with application, providing operations to

  • embed pure expressions ('pure'), and
  • sequence computations and combine their results ('<*>' and 'liftA2').

A minimal complete definition must include implementations of 'pure' and 'liftA2'.

Further, any definition must satisfy the following:

Identity

pure[F](identity) <*> fa == fa

Composition

pure[F](compose) <*> fa <*> fb <*> fc == fa <*> (fb <*> fc)

Homomorphism

pure[F](f) <*> pure(x) == (pure[F](f(x)))

Interchange

u <*> pure(y) == pure[F]((f: String => String) => f(y)) <*> u
Companion
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def liftA2[A, B, C](f: A => B => C): F[A] => F[B] => F[C]

Lift a binary function to actions.

Lift a binary function to actions.

Example
val f = (x: Int) => (y: Int) => x + y
val ff = liftA2[Option](f)
ff(Option(1), Option(2)) == Option(3)
def pure[A](a: A): F[A]

Lift a value.

Lift a value.

Example
pure[Option](1) == Option(1)
(pure(1): Option[Int]) == Option(1)

Extensions

Extensions

extension (fa: F[A])
@targetName("productRight")
def *>[A, B](fb: F[B]): F[B]

Sequence actions, discarding the value of the first argument.

Sequence actions, discarding the value of the first argument.

Example
Option(1) *> Option(2) <* Option(3) == Option(2)
@targetName("productLeft")
def <*[A, B](fb: F[B]): F[A]

Sequence actions, discarding the value of the second argument.

Sequence actions, discarding the value of the second argument.

Example
Option(1) *> Option(2) <* Option(3) == Option(2)
@targetName("apFlipped")
def <**>[A, B](fab: F[A => B]): F[B]

Flipped version of this.ap

Flipped version of this.ap

inline def unless[A, B](cond: Boolean): F[Unit]

Conditional execution of 'Applicative' expressions.

Conditional execution of 'Applicative' expressions.

Example
 doSomething.unless(condFailed) 
inline def when[A, B](cond: Boolean): F[Unit]

Conditional execution of 'Applicative' expressions.

Conditional execution of 'Applicative' expressions.

Example
 doSomething.when(cond) 
extension (fab: F[A => B])
@targetName("ap")
def <*>[A, B](fa: F[A]): F[B]

Sequential application.

Sequential application.

Example
val f = (x: Int) => (y: Int) => x + y
f `<$>` Option(1) <*> Option(2) == Option(3)