A
- The type of the parameterApp
- The unification parameter to more tightly type-constrain Applicatives to themselvespublic interface Applicative<A,App extends Applicative<?,App>> extends Functor<A,App>
The same rules that apply to Functor
apply to Applicative
, along with the following
additional 4 laws:
v.zip(pureId).equals(v)
w.zip(v.zip(u.zip(pureCompose))).equals((w.zip(v)).zip(u))
pureX.zip(pureF).equals(pureFx)
pureY.zip(u).equals(u.zip(pure(f -> f.apply(y))))
Functor
, Applicative
instances that do not satisfy all of the functor laws, as well
as the above applicative laws, are not well-behaved and often break down in surprising ways.
For more information, read about Applicative Functors.
Modifier and Type | Method and Description |
---|---|
default <B> Applicative<B,App> |
discardL(Applicative<B,App> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
default <B> Applicative<A,App> |
discardR(Applicative<B,App> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
default <B> Applicative<B,App> |
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.
|
default <B> Lazy<? extends Applicative<B,App>> |
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,App>> lazyAppFn)
Given a
lazy instance of this applicative over a mapping function, "zip" the two instances together
using whatever application semantics the current applicative supports. |
<B> Applicative<B,App> |
pure(B b)
Lift the value
b into this applicative functor. |
<B> Applicative<B,App> |
zip(Applicative<Fn1<? super A,? extends B>,App> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using
whatever application semantics the current applicative supports.
|
<B> Applicative<B,App> pure(B b)
b
into this applicative functor.B
- the type of the returned applicative's parameterb
- the value<B> Applicative<B,App> zip(Applicative<Fn1<? super A,? extends B>,App> appFn)
B
- the resulting applicative parameter typeappFn
- the other applicative instancedefault <B> Lazy<? extends Applicative<B,App>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,App>> lazyAppFn)
lazy
instance of this applicative over a mapping function, "zip" the two instances together
using whatever application semantics the current applicative supports. This is useful for applicatives that
support lazy evaluation and early termination.default <B> Applicative<B,App> discardL(Applicative<B,App> appB)
Applicative
and appB
, discarding this Applicative's
result and returning appB
. This is generally useful for sequentially performing side-effects.B
- the type of the returned Applicative's parameterappB
- the other Applicativedefault <B> Applicative<A,App> discardR(Applicative<B,App> appB)
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.B
- the type of appB's parameterappB
- the other Applicativedefault <B> Applicative<B,App> fmap(Fn1<? super A,? extends B> fn)