Given a value and a function in the Apply context, applies the function to the value.
ap2 is a binary version of ap, defined in terms of ap.
ap2 is a binary version of ap, defined in terms of ap.
Replaces the A
value in F[A]
with the supplied value.
Replaces the A
value in F[A]
with the supplied value.
Two sequentially dependent Applicatives can be composed.
Two sequentially dependent Applicatives can be composed.
The composition of Applicatives F
and G
, F[G[x]]
, is also an Applicative
Applicative[Option].compose[List].pure(10) = Some(List(10))
Two sequentially dependent Applys can be composed.
Two sequentially dependent Applys can be composed.
The composition of Applys F
and G
, F[G[x]]
, is also an Apply.
Example:
scala> import cats.Apply scala> import cats.implicits._ scala> val ap = Apply[Option].compose[List] scala> val x: Option[List[Int]] = Some(List(1, 2)) scala> val y: Option[List[Int]] = Some(List(10, 20)) scala> ap.map2(x, y)(_ + _) res0: Option[List[Int]] = Some(List(11, 21, 12, 22))
Compose this functor F with a functor G to produce a composite Functor on G[F[_]], with a map method which uses an A => B to map a G[F[A]] to a G[F[B]].
Compose this functor F with a functor G to produce a composite Functor on G[F[_]], with a map method which uses an A => B to map a G[F[A]] to a G[F[B]].
Compose 2 invariant Functors F and G to get a new Invariant Functor for F[G[_]].
Compose 2 invariant Functors F and G to get a new Invariant Functor for F[G[_]].
Compose this functor F with a Contravariant Functor G to produce a new Contravariant Functor on F[G[_]].
Compose the Invariant Functor F with a normal (Covariant) Functor to get a new Invariant Functor for [F[G[_]].
Tuple the values in fa with the result of applying a function with the value
Tuple the values in fa with the result of applying a function with the value
Lift a function f to operate on Functors
Lift a function f to operate on Functors
Applies the pure (binary) function f to the effectful values fa and fb.
Applies the pure (binary) function f to the effectful values fa and fb.
map2 can be seen as a binary version of cats.Functor#map.
Similar to map2 but uses Eval to allow for laziness in the F[B]
argument.
Similar to map2 but uses Eval to allow for laziness in the F[B]
argument. This can allow for "short-circuiting" of computations.
NOTE: the default implementation of map2Eval
does does not short-circuit
computations. For data structures that can benefit from laziness, Apply
instances should override this method.
In the following example, x.map2(bomb)(_ + _)
would result in an error,
but map2Eval
"short-circuits" the computation. x
is None
and thus the
result of bomb
doesn't even need to be evaluated in order to determine
that the result of map2Eval
should be None
.
scala> import cats.{Eval, Later} scala> import cats.implicits._ scala> val bomb: Eval[Option[Int]] = Later(sys.error("boom")) scala> val x: Option[Int] = None scala> x.map2Eval(bomb)(_ + _).value res0: Option[Int] = None
pure
lifts any value into the Applicative Functor.
pure
lifts any value into the Applicative Functor.
Applicative[Option].pure(10) = Some(10)
pureEval
lifts any value into the Applicative Functor.
pureEval
lifts any value into the Applicative Functor.
This variant supports optional laziness.
Given fa
and n
, apply fa
n
times to construct an F[List[A]]
value.
Given fa
and n
, apply fa
n
times to construct an F[List[A]]
value.
Empty the fa of the values, preserving the structure
Empty the fa of the values, preserving the structure