Class Identity<A>
java.lang.Object
com.jnape.palatable.lambda.functor.builtin.Identity<A>
- Type Parameters:
A- the value type
- All Implemented Interfaces:
Applicative<A, Identity<?>>, Functor<A, Identity<?>>, Monad<A, Identity<?>>, MonadRec<A, Identity<?>>, Traversable<A, Identity<?>>
public final class Identity<A>
extends Object
implements MonadRec<A, Identity<?>>, Traversable<A, Identity<?>>
A functor over some value of type
A that can be mapped over and retrieved later.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<B> Identity<B> discardL(Applicative<B, Identity<?>> appB) Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.discardR(Applicative<B, Identity<?>> appB) Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.boolean<B> Identity<B> Chain dependent computations that may continue or short-circuit based on previous results.<B> Identity<B> Covariantly transmute this functor's parameter using the given mapping function.inthashCode()Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.<B> Identity<B> pure(B b) Lift the valuebinto this applicative functor.Retrieve the value.toString()<B> Identity<B> trampolineM(Fn1<? super A, ? extends MonadRec<RecursiveResult<A, B>, Identity<?>>> fn) Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<B, App extends Applicative<?,App>, TravB extends Traversable<B, Identity<?>>, AppTrav extends Applicative<TravB, App>>
AppTravtraverse(Fn1<? super A, ? extends Applicative<B, 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.<B> Identity<B> zip(Applicative<Fn1<? super A, ? extends B>, Identity<?>> appFn) 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
-
Identity
-
-
Method Details
-
runIdentity
-
flatMap
Chain dependent computations that may continue or short-circuit based on previous results. -
fmap
Covariantly transmute this functor's parameter using the given mapping function. Generally this method is specialized to return an instance of the class implementing Functor.- Specified by:
fmapin interfaceApplicative<A, Identity<?>>- Specified by:
fmapin interfaceFunctor<A, Identity<?>>- Specified by:
fmapin interfaceMonad<A, Identity<?>>- Specified by:
fmapin interfaceMonadRec<A, Identity<?>>- Specified by:
fmapin interfaceTraversable<A, Identity<?>>- Type Parameters:
B- the new parameter type- Parameters:
fn- the mapping function- Returns:
- a functor over B (the new parameter type)
-
pure
Lift the valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<A, Identity<?>>- Specified by:
purein interfaceMonad<A, Identity<?>>- Specified by:
purein interfaceMonadRec<A, Identity<?>>- Type Parameters:
B- the type of the returned applicative's parameter- Parameters:
b- the value- Returns:
- an instance of this applicative over b
-
zip
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.- Specified by:
zipin interfaceApplicative<A, Identity<?>>- Specified by:
zipin interfaceMonad<A, Identity<?>>- Specified by:
zipin interfaceMonadRec<A, Identity<?>>- Type Parameters:
B- the resulting applicative parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
public <B> Lazy<Identity<B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A, ? extends B>, Identity<?>>> 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, Identity<?>>- Specified by:
lazyZipin interfaceMonad<A, Identity<?>>- Specified by:
lazyZipin interfaceMonadRec<A, Identity<?>>- Type Parameters:
B- 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.- Specified by:
discardLin interfaceApplicative<A, Identity<?>>- Specified by:
discardLin interfaceMonad<A, Identity<?>>- Specified by:
discardLin interfaceMonadRec<A, Identity<?>>- Type Parameters:
B- the type of the returned Applicative's parameter- Parameters:
appB- the other Applicative- Returns:
- appB
-
discardR
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects. -
traverse
public <B, App extends Applicative<?,App>, TravB extends Traversable<B, Identity<?>>, AppTrav extends Applicative<TravB, AppTrav traverseApp>> (Fn1<? super A, ? extends Applicative<B, 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, Identity<?>>- Type Parameters:
B- 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
-
trampolineM
public <B> Identity<B> trampolineM(Fn1<? super A, ? extends MonadRec<RecursiveResult<A, B>, Identity<?>>> 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, Identity<?>>- Type Parameters:
B- the ultimate resulting carrier type- Parameters:
fn- the function to internally trampoline- Returns:
- the trampolined
MonadRec - See Also:
-
equals
-
hashCode
-
toString
-
pureIdentity
-