A
- the left parameter type, and the type of the stored valueB
- the right (phantom) parameter typepublic final class Const<A,B> extends Object implements MonadRec<B,Const<A,?>>, Bifunctor<A,B,Const<?,?>>, Traversable<B,Const<A,?>>
B
, retaining a value of type A
that
can be retrieved later. This is useful in situations where it is desirable to retain constant information throughout
arbitrary functor transformations, such that at the end of the chain, regardless of how B
has been
altered, A
is still pristine and retrievable.Modifier and Type | Method and Description |
---|---|
<C,D> Const<C,D> |
biMap(Fn1<? super A,? extends C> lFn,
Fn1<? super B,? extends D> rFn)
Dually map covariantly over both the left and right parameters.
|
<Z> Const<Z,B> |
biMapL(Fn1<? super A,? extends Z> fn)
Covariantly map over the left parameter.
|
<C> Const<A,C> |
biMapR(Fn1<? super B,? extends C> fn)
Covariantly map over the right parameter.
|
<C> Const<A,C> |
discardL(Applicative<C,Const<A,?>> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
<C> Const<A,B> |
discardR(Applicative<C,Const<A,?>> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
boolean |
equals(Object other) |
<C> Const<A,C> |
flatMap(Fn1<? super B,? extends Monad<C,Const<A,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
|
<C> Const<A,C> |
fmap(Fn1<? super B,? extends C> fn)
Map over the right parameter.
|
int |
hashCode() |
<C> Lazy<Const<A,C>> |
lazyZip(Lazy<? extends Applicative<Fn1<? super B,? extends C>,Const<A,?>>> 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. |
<C> Const<A,C> |
pure(C c)
Lift the value
b into this applicative functor. |
static <A> Pure<Const<A,?>> |
pureConst(A a)
|
A |
runConst()
Retrieve the stored value.
|
String |
toString() |
<C> Const<A,C> |
trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,Const<A,?>>> fn)
Given some operation yielding a
RecursiveResult inside this MonadRec , internally trampoline the
operation until it yields a termination instruction. |
<C,App extends Applicative<?,App>,TravB extends Traversable<C,Const<A,?>>,AppTrav extends Applicative<TravB,App>> |
traverse(Fn1<? super B,? extends Applicative<C,App>> fn,
Fn1<? super TravB,? extends AppTrav> pure)
Apply
fn to each element of this traversable from left to right, and collapse the results into
a single resulting applicative, potentially with the assistance of the applicative's pure function. |
<C> Const<A,C> |
zip(Applicative<Fn1<? super B,? extends C>,Const<A,?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using
whatever application semantics the current applicative supports.
|
public Const(A a)
public A runConst()
public <C> Const<A,C> fmap(Fn1<? super B,? extends C> fn)
B
is never actually known quantity outside of a type
signature, this is effectively a no-op that serves only to alter Const's
type signature.fmap
in interface Applicative<B,Const<A,?>>
fmap
in interface Functor<B,Const<A,?>>
fmap
in interface Monad<B,Const<A,?>>
fmap
in interface MonadRec<B,Const<A,?>>
fmap
in interface Traversable<B,Const<A,?>>
C
- the new right parameter typefn
- the mapping functionpublic <C> Const<A,C> pure(C c)
b
into this applicative functor.pure
in interface Applicative<B,Const<A,?>>
pure
in interface Monad<B,Const<A,?>>
pure
in interface MonadRec<B,Const<A,?>>
C
- the type of the returned applicative's parameterc
- the valuepublic <C> Const<A,C> zip(Applicative<Fn1<? super B,? extends C>,Const<A,?>> appFn)
zip
in interface Applicative<B,Const<A,?>>
zip
in interface Monad<B,Const<A,?>>
zip
in interface MonadRec<B,Const<A,?>>
C
- the resulting applicative parameter typeappFn
- the other applicative instancepublic <C> Lazy<Const<A,C>> lazyZip(Lazy<? extends Applicative<Fn1<? super B,? extends C>,Const<A,?>>> 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.lazyZip
in interface Applicative<B,Const<A,?>>
lazyZip
in interface Monad<B,Const<A,?>>
lazyZip
in interface MonadRec<B,Const<A,?>>
C
- the resulting applicative parameter typelazyAppFn
- the lazy other applicative instanceMaybe
,
Either
public <C> Const<A,C> discardL(Applicative<C,Const<A,?>> appB)
Applicative
and appB
, discarding this Applicative's
result and returning appB
. This is generally useful for sequentially performing side-effects.discardL
in interface Applicative<B,Const<A,?>>
discardL
in interface Monad<B,Const<A,?>>
discardL
in interface MonadRec<B,Const<A,?>>
C
- the type of the returned Applicative's parameterappB
- the other Applicativepublic <C> Const<A,B> discardR(Applicative<C,Const<A,?>> appB)
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.public <C> Const<A,C> flatMap(Fn1<? super B,? extends Monad<C,Const<A,?>>> f)
public <C> Const<A,C> trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,Const<A,?>>> fn)
RecursiveResult
inside this MonadRec
, internally trampoline the
operation until it yields a termination
instruction.
Stack-safety depends on implementations guaranteeing that the growth of the call stack is a constant factor independent of the number of invocations of the operation. For various examples of how this can be achieved in stereotypical circumstances, see the referenced types.
trampolineM
in interface MonadRec<B,Const<A,?>>
C
- the ultimate resulting carrier typefn
- the function to internally trampolineMonadRec
for a basic implementation
,
for a {@link CoProduct2 coproduct} implementation
,
for an implementation leveraging an already stack-safe {@link Monad#flatMap(Fn1)}
,
for a {@link MonadT monad transformer} implementation
public <C,App extends Applicative<?,App>,TravB extends Traversable<C,Const<A,?>>,AppTrav extends Applicative<TravB,App>> AppTrav traverse(Fn1<? super B,? extends Applicative<C,App>> fn, Fn1<? super TravB,? extends AppTrav> pure)
fn
to each element of this traversable from left to right, and collapse the results into
a single resulting applicative, potentially with the assistance of the applicative's pure function.traverse
in interface Traversable<B,Const<A,?>>
C
- the resulting element typeApp
- the result applicative typeTravB
- this Traversable instance over BAppTrav
- the full inferred resulting type from the traversalfn
- the function to applypure
- the applicative pure functionpublic <Z> Const<Z,B> biMapL(Fn1<? super A,? extends Z> fn)
biMapL
in interface Bifunctor<A,B,Const<?,?>>
biMapL
in interface BoundedBifunctor<A,B,Object,Object,Const<?,?>>
Z
- the new left parameter typefn
- the mapping functionpublic <C> Const<A,C> biMapR(Fn1<? super B,? extends C> fn)
biMapR(f) == fmap(f)
.biMapR
in interface Bifunctor<A,B,Const<?,?>>
biMapR
in interface BoundedBifunctor<A,B,Object,Object,Const<?,?>>
C
- the new right parameter typefn
- the mapping functionpublic <C,D> Const<C,D> biMap(Fn1<? super A,? extends C> lFn, Fn1<? super B,? extends D> rFn)
biMapL(lFn).biMapR(rFn)
.biMap
in interface Bifunctor<A,B,Const<?,?>>
biMap
in interface BoundedBifunctor<A,B,Object,Object,Const<?,?>>
C
- the new left parameter typeD
- the new right parameter typelFn
- the left parameter mapping functionrFn
- the right parameter mapping function