Class MaybeT<M extends MonadRec<?,M>,A>
- java.lang.Object
-
- com.jnape.palatable.lambda.monad.transformer.builtin.MaybeT<M,A>
-
- Type Parameters:
M- the outerstack-safe monadA- the carrier type
- All Implemented Interfaces:
Applicative<A,MaybeT<M,?>>,Functor<A,MaybeT<M,?>>,Monad<A,MaybeT<M,?>>,MonadBase<M,A,MaybeT<?,?>>,MonadError<Unit,A,MaybeT<M,?>>,MonadRec<A,MaybeT<M,?>>,MonadT<M,A,MaybeT<M,?>,MaybeT<?,?>>
public final class MaybeT<M extends MonadRec<?,M>,A> extends java.lang.Object implements MonadT<M,A,MaybeT<M,?>,MaybeT<?,?>>, MonadError<Unit,A,MaybeT<M,?>>
Amonad transformerforMaybe.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MaybeT<M,A>catchError(Fn1<? super Unit,? extends Monad<A,MaybeT<M,?>>> recoveryFn)<B> MaybeT<M,B>discardL(Applicative<B,MaybeT<M,?>> appB)Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.<B> MaybeT<M,A>discardR(Applicative<B,MaybeT<M,?>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.booleanequals(java.lang.Object other)MaybeT<M,A>filter(Fn1<? super A,? extends java.lang.Boolean> predicate)If the embedded value is present and satisfiespredicatethen returnjustthe embedded value<B> MaybeT<M,B>flatMap(Fn1<? super A,? extends Monad<B,MaybeT<M,?>>> f)Chain dependent computations that may continue or short-circuit based on previous results.<B> MaybeT<M,B>fmap(Fn1<? super A,? extends B> fn)Covariantly transmute this functor's parameter using the given mapping function.inthashCode()<B> Lazy<MaybeT<M,B>>lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,MaybeT<M,?>>> lazyAppFn)Given alazyinstance 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>>
MaybeT<N,B>lift(MonadRec<B,N> mb)static Lift<MaybeT<?,?>>liftMaybeT()static <M extends MonadRec<?,M>,A>
MaybeT<M,A>maybeT(MonadRec<Maybe<A>,M> mma)MaybeT<M,A>or(MaybeT<M,A> other)<B> MaybeT<M,B>pure(B b)Lift the valuebinto this applicative functor.static <M extends MonadRec<?,M>>
Pure<MaybeT<M,?>>pureMaybeT(Pure<M> pureM)<MMA extends MonadRec<Maybe<A>,M>>
MMArunMaybeT()Recover the full structure of the embeddedMonad.MaybeT<M,A>throwError(Unit unit)Throw an error value of typeEinto themonad.java.lang.StringtoString()<B> MaybeT<M,B>trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,MaybeT<M,?>>> fn)Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<B> MaybeT<M,B>zip(Applicative<Fn1<? super A,? extends B>,MaybeT<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
-
runMaybeT
public <MMA extends MonadRec<Maybe<A>,M>> MMA runMaybeT()
Recover the full structure of the embeddedMonad.- Type Parameters:
MMA- the witnessed target type- Returns:
- the embedded
Monad
-
filter
public MaybeT<M,A> filter(Fn1<? super A,? extends java.lang.Boolean> predicate)
If the embedded value is present and satisfiespredicatethen returnjustthe embedded value- Parameters:
predicate- the predicate to apply to the embedded value- Returns:
- maybe the satisfied value embedded under M
-
throwError
public MaybeT<M,A> throwError(Unit unit)
Throw an error value of typeEinto themonad.- Specified by:
throwErrorin interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Parameters:
unit- the error type- Returns:
- the
monad
-
catchError
public MaybeT<M,A> catchError(Fn1<? super Unit,? extends Monad<A,MaybeT<M,?>>> recoveryFn)
- Specified by:
catchErrorin interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Parameters:
recoveryFn- the catch function- Returns:
- the recovered
Monad
-
lift
public <B,N extends MonadRec<?,N>> MaybeT<N,B> lift(MonadRec<B,N> mb)
- Specified by:
liftin interfaceMonadBase<M extends MonadRec<?,M>,A,MaybeT<?,?>>- Specified by:
liftin interfaceMonadT<M extends MonadRec<?,M>,A,MaybeT<M extends MonadRec<?,M>,?>,MaybeT<?,?>>- Type Parameters:
B- theMonadReccarrier typeN- the argumentMonadRecwitness- Parameters:
mb- the argumentMonadRec- Returns:
- the new
MonadBase
-
fmap
public <B> MaybeT<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:
fmapin interfaceApplicative<M extends MonadRec<?,M>,A>- Specified by:
fmapin interfaceFunctor<M extends MonadRec<?,M>,A>- Specified by:
fmapin interfaceMonad<M extends MonadRec<?,M>,A>- Specified by:
fmapin interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Specified by:
fmapin interfaceMonadRec<M extends MonadRec<?,M>,A>- Specified by:
fmapin interfaceMonadT<M extends MonadRec<?,M>,A,MaybeT<M extends MonadRec<?,M>,?>,MaybeT<?,?>>- Type Parameters:
B- the new parameter type- Parameters:
fn- the mapping function- Returns:
- a functor over B (the new parameter type)
-
pure
public <B> MaybeT<M,B> pure(B b)
Lift the valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<M extends MonadRec<?,M>,A>- Specified by:
purein interfaceMonad<M extends MonadRec<?,M>,A>- Specified by:
purein interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Specified by:
purein interfaceMonadRec<M extends MonadRec<?,M>,A>- Specified by:
purein interfaceMonadT<M extends MonadRec<?,M>,A,MaybeT<M extends MonadRec<?,M>,?>,MaybeT<?,?>>- Type Parameters:
B- the type of the returned applicative's parameter- Parameters:
b- the value- Returns:
- an instance of this applicative over b
-
zip
public <B> MaybeT<M,B> zip(Applicative<Fn1<? super A,? extends B>,MaybeT<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:
zipin interfaceApplicative<M extends MonadRec<?,M>,A>- Specified by:
zipin interfaceMonad<M extends MonadRec<?,M>,A>- Specified by:
zipin interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Specified by:
zipin interfaceMonadRec<M extends MonadRec<?,M>,A>- Specified by:
zipin interfaceMonadT<M extends MonadRec<?,M>,A,MaybeT<M extends MonadRec<?,M>,?>,MaybeT<?,?>>- Type Parameters:
B- the resulting applicative parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
public <B> Lazy<MaybeT<M,B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,MaybeT<M,?>>> 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<M extends MonadRec<?,M>,A>- Specified by:
lazyZipin interfaceMonad<M extends MonadRec<?,M>,A>- Specified by:
lazyZipin interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Specified by:
lazyZipin interfaceMonadRec<M extends MonadRec<?,M>,A>- Specified by:
lazyZipin interfaceMonadT<M extends MonadRec<?,M>,A,MaybeT<M extends MonadRec<?,M>,?>,MaybeT<?,?>>- Type Parameters:
B- the resulting applicative parameter type- Parameters:
lazyAppFn- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
Maybe,Either
-
flatMap
public <B> MaybeT<M,B> flatMap(Fn1<? super A,? extends Monad<B,MaybeT<M,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMapin interfaceMonad<M extends MonadRec<?,M>,A>- Specified by:
flatMapin interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Specified by:
flatMapin interfaceMonadRec<M extends MonadRec<?,M>,A>- Specified by:
flatMapin interfaceMonadT<M extends MonadRec<?,M>,A,MaybeT<M extends MonadRec<?,M>,?>,MaybeT<?,?>>- Type Parameters:
B- the resulting monad parameter type- Parameters:
f- the dependent computation over A- Returns:
- the new monad instance
-
trampolineM
public <B> MaybeT<M,B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,MaybeT<M,?>>> 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<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
-
discardL
public <B> MaybeT<M,B> discardL(Applicative<B,MaybeT<M,?>> appB)
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.- Specified by:
discardLin interfaceApplicative<M extends MonadRec<?,M>,A>- Specified by:
discardLin interfaceMonad<M extends MonadRec<?,M>,A>- Specified by:
discardLin interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Specified by:
discardLin interfaceMonadRec<M extends MonadRec<?,M>,A>- Specified by:
discardLin interfaceMonadT<M extends MonadRec<?,M>,A,MaybeT<M extends MonadRec<?,M>,?>,MaybeT<?,?>>- Type Parameters:
B- the type of the returned Applicative's parameter- Parameters:
appB- the other Applicative- Returns:
- appB
-
discardR
public <B> MaybeT<M,A> discardR(Applicative<B,MaybeT<M,?>> appB)
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<M extends MonadRec<?,M>,A>- Specified by:
discardRin interfaceMonad<M extends MonadRec<?,M>,A>- Specified by:
discardRin interfaceMonadError<Unit,A,MaybeT<M extends MonadRec<?,M>,?>>- Specified by:
discardRin interfaceMonadRec<M extends MonadRec<?,M>,A>- Specified by:
discardRin interfaceMonadT<M extends MonadRec<?,M>,A,MaybeT<M extends MonadRec<?,M>,?>,MaybeT<?,?>>- 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-