Class Const<A,B>
java.lang.Object
com.jnape.palatable.lambda.functor.builtin.Const<A,B>
- Type Parameters:
A- the left parameter type, and the type of the stored valueB- the right (phantom) parameter type
- All Implemented Interfaces:
Applicative<B, Const<A,?>>, Bifunctor<A, B, Const<?, ?>>, BoundedBifunctor<A, B, Object, Object, Const<?, ?>>, Functor<B, Const<A, ?>>, Monad<B, Const<A, ?>>, MonadRec<B, Const<A, ?>>, Traversable<B, Const<A, ?>>
public final class Const<A,B>
extends Object
implements MonadRec<B, Const<A,?>>, Bifunctor<A, B, Const<?,?>>, Traversable<B, Const<A,?>>
A (surprisingly useful) functor over some phantom type
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.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<C,D> Const <C, D> Dually map covariantly over both the left and right parameters.Covariantly map over the left parameter.Covariantly map over the right parameter.discardL(Applicative<C, Const<A, ?>> appB) Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.discardR(Applicative<C, Const<A, ?>> appB) Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.booleanChain dependent computations that may continue or short-circuit based on previous results.Map over the right parameter.inthashCode()Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.pure(C c) Lift the valuebinto this applicative functor.pureConst(A a) runConst()Retrieve the stored value.toString()trampolineM(Fn1<? super B, ? extends MonadRec<RecursiveResult<B, C>, Const<A, ?>>> fn) Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<C, App extends Applicative<?,App>, TravB extends Traversable<C, Const<A, ?>>, AppTrav extends Applicative<TravB, App>>
AppTravtraverse(Fn1<? super B, ? extends Applicative<C, App>> fn, Fn1<? super TravB, ? extends AppTrav> pure) Applyfnto 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.Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
Field Details
-
a
-
-
Constructor Details
-
Const
-
-
Method Details
-
runConst
-
fmap
Map over the right parameter. Note that becauseBis never actually known quantity outside of a type signature, this is effectively a no-op that serves only to alterConst'stype signature.- Specified by:
fmapin interfaceApplicative<A,B> - Specified by:
fmapin interfaceFunctor<A,B> - Specified by:
fmapin interfaceMonad<A,B> - Specified by:
fmapin interfaceMonadRec<A,B> - Specified by:
fmapin interfaceTraversable<A,B> - Type Parameters:
C- the new right parameter type- Parameters:
fn- the mapping function- Returns:
- a Const over A (the same value) and C (the new phantom parameter)
-
pure
Lift the valuebinto this applicative functor. -
zip
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. -
lazyZip
public <C> Lazy<Const<A,C>> lazyZip(Lazy<? extends Applicative<Fn1<? super B, ? extends C>, Const<A, ?>>> lazyAppFn) Given alazyinstance 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.- Specified by:
lazyZipin interfaceApplicative<A,B> - Specified by:
lazyZipin interfaceMonad<A,B> - Specified by:
lazyZipin interfaceMonadRec<A,B> - Type Parameters:
C- the resulting applicative parameter type- Parameters:
lazyAppFn- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
-
discardL
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects. -
discardR
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects. -
flatMap
Chain dependent computations that may continue or short-circuit based on previous results. -
trampolineM
public <C> Const<A,C> trampolineM(Fn1<? super B, ? extends MonadRec<RecursiveResult<B, C>, Const<A, ?>>> fn) Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.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.
- Specified by:
trampolineMin interfaceMonadRec<A,B> - Type Parameters:
C- the ultimate resulting carrier type- Parameters:
fn- the function to internally trampoline- Returns:
- the trampolined
MonadRec - See Also:
-
traverse
public <C, App extends Applicative<?,App>, TravB extends Traversable<C, Const<A, AppTrav traverse?>>, AppTrav extends Applicative<TravB, App>> (Fn1<? super B, ? extends Applicative<C, App>> fn, Fn1<? super TravB, ? extends AppTrav> pure) Applyfnto 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.- Specified by:
traversein interfaceTraversable<A,B> - Type Parameters:
C- the resulting element typeApp- the result applicative typeTravB- this Traversable instance over BAppTrav- the full inferred resulting type from the traversal- Parameters:
fn- the function to applypure- the applicative pure function- Returns:
- the traversed Traversable, wrapped inside an applicative
-
biMapL
Covariantly map over the left parameter.- Specified by:
biMapLin interfaceBifunctor<A, B, Const<?,?>> - Specified by:
biMapLin interfaceBoundedBifunctor<A, B, Object, Object, Const<?,?>> - Type Parameters:
Z- the new left parameter type- Parameters:
fn- the mapping function- Returns:
- a bifunctor over C (the new left parameter) and B (the same right parameter)
-
biMapR
Covariantly map over the right parameter. For all bifunctors that are also functors, it should hold thatbiMapR(f) == fmap(f).- Specified by:
biMapRin interfaceBifunctor<A, B, Const<?,?>> - Specified by:
biMapRin interfaceBoundedBifunctor<A, B, Object, Object, Const<?,?>> - Type Parameters:
C- the new right parameter type- Parameters:
fn- the mapping function- Returns:
- a bifunctor over A (the same left parameter) and C (the new right parameter)
-
biMap
Dually map covariantly over both the left and right parameters. This is isomorphic tobiMapL(lFn).biMapR(rFn).- Specified by:
biMapin interfaceBifunctor<A, B, Const<?,?>> - Specified by:
biMapin interfaceBoundedBifunctor<A, B, Object, Object, Const<?,?>> - Type Parameters:
C- the new left parameter typeD- the new right parameter type- Parameters:
lFn- the left parameter mapping functionrFn- the right parameter mapping function- Returns:
- a bifunctor over C (the new left parameter type) and D (the new right parameter type)
-
equals
-
hashCode
-
toString
-
pureConst
-