Class IdentityT<M extends MonadRec<?,M>,A>
- java.lang.Object
-
- com.jnape.palatable.lambda.monad.transformer.builtin.IdentityT<M,A>
-
- Type Parameters:
M
- the outerstack-safe monad
A
- the carrier type
- All Implemented Interfaces:
Applicative<A,IdentityT<M,?>>
,Functor<A,IdentityT<M,?>>
,Monad<A,IdentityT<M,?>>
,MonadBase<M,A,IdentityT<?,?>>
,MonadRec<A,IdentityT<M,?>>
,MonadT<M,A,IdentityT<M,?>,IdentityT<?,?>>
public final class IdentityT<M extends MonadRec<?,M>,A> extends java.lang.Object implements MonadT<M,A,IdentityT<M,?>,IdentityT<?,?>>
Amonad transformer
forIdentity
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <B> IdentityT<M,B>
discardL(Applicative<B,IdentityT<M,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.<B> IdentityT<M,A>
discardR(Applicative<B,IdentityT<M,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.boolean
equals(java.lang.Object other)
<B> IdentityT<M,B>
flatMap(Fn1<? super A,? extends Monad<B,IdentityT<M,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.<B> IdentityT<M,B>
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.int
hashCode()
static <M extends MonadRec<?,M>,A>
IdentityT<M,A>identityT(MonadRec<Identity<A>,M> mia)
<B> Lazy<IdentityT<M,B>>
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,IdentityT<M,?>>> lazyAppFn)
Given alazy
instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.<B,N extends MonadRec<?,N>>
IdentityT<N,B>lift(MonadRec<B,N> mb)
static Lift<IdentityT<?,?>>
liftIdentityT()
<B> IdentityT<M,B>
pure(B b)
Lift the valueb
into this applicative functor.static <M extends MonadRec<?,M>>
Pure<IdentityT<M,?>>pureIdentityT(Pure<M> pureM)
<MIA extends MonadRec<Identity<A>,M>>
MIArunIdentityT()
Recover the full structure of the embeddedMonad
.java.lang.String
toString()
<B> IdentityT<M,B>
trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,IdentityT<M,?>>> fn)
Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.<B> IdentityT<M,B>
zip(Applicative<Fn1<? super A,? extends B>,IdentityT<M,?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
-
-
Method Detail
-
runIdentityT
public <MIA extends MonadRec<Identity<A>,M>> MIA runIdentityT()
Recover the full structure of the embeddedMonad
.- Type Parameters:
MIA
- the witnessed target type- Returns:
- the embedded
Monad
-
lift
public <B,N extends MonadRec<?,N>> IdentityT<N,B> lift(MonadRec<B,N> mb)
- Specified by:
lift
in interfaceMonadBase<M extends MonadRec<?,M>,A,IdentityT<?,?>>
- Specified by:
lift
in interfaceMonadT<M extends MonadRec<?,M>,A,IdentityT<M extends MonadRec<?,M>,?>,IdentityT<?,?>>
- Type Parameters:
B
- theMonadRec
carrier typeN
- the argumentMonadRec
witness- Parameters:
mb
- the argumentMonadRec
- Returns:
- the new
MonadBase
-
flatMap
public <B> IdentityT<M,B> flatMap(Fn1<? super A,? extends Monad<B,IdentityT<M,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMap
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
flatMap
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Specified by:
flatMap
in interfaceMonadT<M extends MonadRec<?,M>,A,IdentityT<M extends MonadRec<?,M>,?>,IdentityT<?,?>>
- Type Parameters:
B
- the resulting monad parameter type- Parameters:
f
- the dependent computation over A- Returns:
- the new monad instance
-
trampolineM
public <B> IdentityT<M,B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,IdentityT<M,?>>> fn)
Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
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.
- Specified by:
trampolineM
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Type Parameters:
B
- the ultimate resulting carrier type- Parameters:
fn
- the function to internally trampoline- Returns:
- the trampolined
MonadRec
- See Also:
for a basic implementation
,for a implementation
,for an implementation leveraging an already stack-safe
,for a implementation
-
pure
public <B> IdentityT<M,B> pure(B b)
Lift the valueb
into this applicative functor.- Specified by:
pure
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
pure
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
pure
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Specified by:
pure
in interfaceMonadT<M extends MonadRec<?,M>,A,IdentityT<M extends MonadRec<?,M>,?>,IdentityT<?,?>>
- Type Parameters:
B
- the type of the returned applicative's parameter- Parameters:
b
- the value- Returns:
- an instance of this applicative over b
-
fmap
public <B> IdentityT<M,B> fmap(Fn1<? super A,? extends B> fn)
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:
fmap
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
fmap
in interfaceFunctor<M extends MonadRec<?,M>,A>
- Specified by:
fmap
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
fmap
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Specified by:
fmap
in interfaceMonadT<M extends MonadRec<?,M>,A,IdentityT<M extends MonadRec<?,M>,?>,IdentityT<?,?>>
- Type Parameters:
B
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- a functor over B (the new parameter type)
-
zip
public <B> IdentityT<M,B> zip(Applicative<Fn1<? super A,? extends B>,IdentityT<M,?>> appFn)
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:
zip
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
zip
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
zip
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Specified by:
zip
in interfaceMonadT<M extends MonadRec<?,M>,A,IdentityT<M extends MonadRec<?,M>,?>,IdentityT<?,?>>
- Type Parameters:
B
- the resulting applicative parameter type- Parameters:
appFn
- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
public <B> Lazy<IdentityT<M,B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,IdentityT<M,?>>> lazyAppFn)
Given alazy
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.- Specified by:
lazyZip
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
lazyZip
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
lazyZip
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Specified by:
lazyZip
in interfaceMonadT<M extends MonadRec<?,M>,A,IdentityT<M extends MonadRec<?,M>,?>,IdentityT<?,?>>
- Type Parameters:
B
- the resulting applicative parameter type- Parameters:
lazyAppFn
- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
Maybe
,Either
-
discardL
public <B> IdentityT<M,B> discardL(Applicative<B,IdentityT<M,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
. This is generally useful for sequentially performing side-effects.- Specified by:
discardL
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
discardL
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
discardL
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Specified by:
discardL
in interfaceMonadT<M extends MonadRec<?,M>,A,IdentityT<M extends MonadRec<?,M>,?>,IdentityT<?,?>>
- Type Parameters:
B
- the type of the returned Applicative's parameter- Parameters:
appB
- the other Applicative- Returns:
- appB
-
discardR
public <B> IdentityT<M,A> discardR(Applicative<B,IdentityT<M,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
. This is generally useful for sequentially performing side-effects.- Specified by:
discardR
in interfaceApplicative<M extends MonadRec<?,M>,A>
- Specified by:
discardR
in interfaceMonad<M extends MonadRec<?,M>,A>
- Specified by:
discardR
in interfaceMonadRec<M extends MonadRec<?,M>,A>
- Specified by:
discardR
in interfaceMonadT<M extends MonadRec<?,M>,A,IdentityT<M extends MonadRec<?,M>,?>,IdentityT<?,?>>
- Type Parameters:
B
- the type of appB's parameter- Parameters:
appB
- the other Applicative- Returns:
- this Applicative
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
identityT
public static <M extends MonadRec<?,M>,A> IdentityT<M,A> identityT(MonadRec<Identity<A>,M> mia)
-
pureIdentityT
public static <M extends MonadRec<?,M>> Pure<IdentityT<M,?>> pureIdentityT(Pure<M> pureM)
-
-