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 monad
A
- 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 Object
implements MonadT<M,A,MaybeT<M,?>,MaybeT<?,?>>, MonadError<Unit,A,MaybeT<M,?>>
A
monad transformer
for Maybe
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondiscardL
(Applicative<B, MaybeT<M, ?>> appB) Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.discardR
(Applicative<B, MaybeT<M, ?>> appB) Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.boolean
If the embedded value is present and satisfiespredicate
then returnjust
the embedded valueChain dependent computations that may continue or short-circuit based on previous results.Covariantly transmute this functor's parameter using the given mapping function.int
hashCode()
Given alazy
instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.pure
(B b) Lift the valueb
into this applicative functor.pureMaybeT
(Pure<M> pureM) Recover the full structure of the embeddedMonad
.throwError
(Unit unit) Throw an error value of typeE
into themonad
.toString()
trampolineM
(Fn1<? super A, ? extends MonadRec<RecursiveResult<A, B>, MaybeT<M, ?>>> fn) Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.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
-
mma
-
-
Constructor Details
-
MaybeT
-
-
Method Details
-
runMaybeT
Recover the full structure of the embeddedMonad
.- Type Parameters:
MMA
- the witnessed target type- Returns:
- the embedded
Monad
-
filter
If the embedded value is present and satisfiespredicate
then returnjust
the embedded value- Parameters:
predicate
- the predicate to apply to the embedded value- Returns:
- maybe the satisfied value embedded under M
-
or
-
throwError
Throw an error value of typeE
into themonad
.- Specified by:
throwError
in interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Parameters:
unit
- the error type- Returns:
- the
monad
-
catchError
- Specified by:
catchError
in interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Parameters:
recoveryFn
- the catch function- Returns:
- the recovered
Monad
-
lift
- Specified by:
lift
in interfaceMonadBase<M extends MonadRec<?,
M>, A, MaybeT<?, ?>> - Specified by:
lift
in interfaceMonadT<M extends MonadRec<?,
M>, A, MaybeT<M extends MonadRec<?, M>, ?>, MaybeT<?, ?>> - Type Parameters:
B
- theMonadRec
carrier typeN
- the argumentMonadRec
witness- Parameters:
mb
- the argumentMonadRec
- Returns:
- the new
MonadBase
-
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:
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 interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Specified by:
fmap
in interfaceMonadRec<M extends MonadRec<?,
M>, A> - Specified by:
fmap
in 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
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 interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Specified by:
pure
in interfaceMonadRec<M extends MonadRec<?,
M>, A> - Specified by:
pure
in 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
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 interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Specified by:
zip
in interfaceMonadRec<M extends MonadRec<?,
M>, A> - Specified by:
zip
in 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 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 interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Specified by:
lazyZip
in interfaceMonadRec<M extends MonadRec<?,
M>, A> - Specified by:
lazyZip
in 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:
-
flatMap
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 interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Specified by:
flatMap
in interfaceMonadRec<M extends MonadRec<?,
M>, A> - Specified by:
flatMap
in 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 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.
-
discardL
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 interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Specified by:
discardL
in interfaceMonadRec<M extends MonadRec<?,
M>, A> - Specified by:
discardL
in 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
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 interfaceMonadError<Unit,
A, MaybeT<M extends MonadRec<?, M>, ?>> - Specified by:
discardR
in interfaceMonadRec<M extends MonadRec<?,
M>, A> - Specified by:
discardR
in 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
-
hashCode
public int hashCode() -
toString
-
maybeT
-
pureMaybeT
-
liftMaybeT
-