Class ReaderT<R,M extends MonadRec<?,M>,A>
- java.lang.Object
-
- com.jnape.palatable.lambda.monad.transformer.builtin.ReaderT<R,M,A>
-
- Type Parameters:
R
- the input typeM
- the returnedMonadRec
A
- the embedded output type
- All Implemented Interfaces:
Applicative<A,ReaderT<R,M,?>>
,Cartesian<R,A,ReaderT<?,M,?>>
,Contravariant<R,Profunctor<?,A,ReaderT<?,M,?>>>
,Functor<A,ReaderT<R,M,?>>
,Profunctor<R,A,ReaderT<?,M,?>>
,Monad<A,ReaderT<R,M,?>>
,MonadBase<M,A,ReaderT<R,?,?>>
,MonadReader<R,A,ReaderT<R,M,?>>
,MonadRec<A,ReaderT<R,M,?>>
,MonadT<M,A,ReaderT<R,M,?>,ReaderT<R,?,?>>
public final class ReaderT<R,M extends MonadRec<?,M>,A> extends java.lang.Object implements MonadReader<R,A,ReaderT<R,M,?>>, Cartesian<R,A,ReaderT<?,M,?>>, MonadT<M,A,ReaderT<R,M,?>,ReaderT<R,?,?>>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <B> ReaderT<R,M,B>
and(ReaderT<A,M,B> amb)
Left-to-right composition betweenReaderT
instances running under the same effect and compatible between their inputs and outputs.static <R,M extends MonadRec<?,M>>
ReaderT<R,M,R>ask(Pure<M> pureM)
Given aPure
ask will give you access to the input within the monadic embeddingReaderT<R,M,Tuple2<R,A>>
carry()
Pair the covariantly-positioned carrier type with the contravariantly-positioned carrier type.<C> ReaderT<Tuple2<C,R>,M,Tuple2<C,A>>
cartesian()
Pair some typeC
to this profunctor's carrier types.<Q> ReaderT<Q,M,A>
contraMap(Fn1<? super Q,? extends R> fn)
Contravariantly mapA <- B
.<Q,B>
ReaderT<Q,M,B>diMap(Fn1<? super Q,? extends R> lFn, Fn1<? super A,? extends B> rFn)
Dually map contravariantly over the left parameter and covariantly over the right parameter.<Q> ReaderT<Q,M,A>
diMapL(Fn1<? super Q,? extends R> fn)
Contravariantly map over the left parameter.<B> ReaderT<R,M,B>
diMapR(Fn1<? super A,? extends B> fn)
Covariantly map over the right parameter.<B> ReaderT<R,M,B>
discardL(Applicative<B,ReaderT<R,M,?>> appB)
Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.<B> ReaderT<R,M,A>
discardR(Applicative<B,ReaderT<R,M,?>> appB)
Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.<B> ReaderT<R,M,B>
flatMap(Fn1<? super A,? extends Monad<B,ReaderT<R,M,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.<B> ReaderT<R,M,B>
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.<B> Lazy<ReaderT<R,M,B>>
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,ReaderT<R,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>>
ReaderT<R,N,B>lift(MonadRec<B,N> mb)
static <R> Lift<ReaderT<R,?,?>>
liftReaderT()
ReaderT<R,M,A>
local(Fn1<? super R,? extends R> fn)
Modify thisMonadReader's
environment after reading it but before running the effect.<MA extends MonadRec<A,M>,N extends MonadRec<?,N>,B>
ReaderT<R,N,B>mapReaderT(Fn1<? super MA,? extends MonadRec<B,N>> fn)
<B> ReaderT<R,M,B>
pure(B b)
Lift the valueb
into this applicative functor.static <R,M extends MonadRec<?,M>>
Pure<ReaderT<R,M,?>>pureReaderT(Pure<M> pureM)
static <R,M extends MonadRec<?,M>,A>
ReaderT<R,M,A>readerT(Fn1<? super R,? extends MonadRec<A,M>> fn)
<MA extends MonadRec<A,M>>
MArunReaderT(R r)
Run the computation represented by thisReaderT
.<B> ReaderT<R,M,B>
trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,ReaderT<R,M,?>>> fn)
Given some operation yielding aRecursiveResult
inside thisMonadRec
, internally trampoline the operation until it yields atermination
instruction.<B> ReaderT<R,M,B>
zip(Applicative<Fn1<? super A,? extends B>,ReaderT<R,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
-
runReaderT
public <MA extends MonadRec<A,M>> MA runReaderT(R r)
Run the computation represented by thisReaderT
.- Type Parameters:
MA
- the witnessed target type- Parameters:
r
- the input- Returns:
- the embedded
MonadRec
-
mapReaderT
public <MA extends MonadRec<A,M>,N extends MonadRec<?,N>,B> ReaderT<R,N,B> mapReaderT(Fn1<? super MA,? extends MonadRec<B,N>> fn)
-
and
public <B> ReaderT<R,M,B> and(ReaderT<A,M,B> amb)
Left-to-right composition betweenReaderT
instances running under the same effect and compatible between their inputs and outputs.
-
local
public ReaderT<R,M,A> local(Fn1<? super R,? extends R> fn)
Modify thisMonadReader's
environment after reading it but before running the effect.- Specified by:
local
in interfaceMonadReader<R,M extends MonadRec<?,M>,A>
- Parameters:
fn
- the modification function- Returns:
- the
MonadReader
with a modified environment
-
lift
public <B,N extends MonadRec<?,N>> ReaderT<R,N,B> lift(MonadRec<B,N> mb)
- Specified by:
lift
in interfaceMonadBase<R,M extends MonadRec<?,M>,A>
- Specified by:
lift
in interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>
- Type Parameters:
B
- theMonadRec
carrier typeN
- the argumentMonadRec
witness- Parameters:
mb
- the argumentMonadRec
- Returns:
- the new
MonadBase
-
flatMap
public <B> ReaderT<R,M,B> flatMap(Fn1<? super A,? extends Monad<B,ReaderT<R,M,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMap
in interfaceMonad<R,M extends MonadRec<?,M>>
- Specified by:
flatMap
in interfaceMonadReader<R,M extends MonadRec<?,M>,A>
- Specified by:
flatMap
in interfaceMonadRec<R,M extends MonadRec<?,M>>
- Specified by:
flatMap
in interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>
- Type Parameters:
B
- the resulting monad parameter type- Parameters:
f
- the dependent computation over A- Returns:
- the new monad instance
-
trampolineM
public <B> ReaderT<R,M,B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,ReaderT<R,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<R,M extends MonadRec<?,M>>
- 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> ReaderT<R,M,B> pure(B b)
Lift the valueb
into this applicative functor.- Specified by:
pure
in interfaceApplicative<R,M extends MonadRec<?,M>>
- Specified by:
pure
in interfaceMonad<R,M extends MonadRec<?,M>>
- Specified by:
pure
in interfaceMonadReader<R,M extends MonadRec<?,M>,A>
- Specified by:
pure
in interfaceMonadRec<R,M extends MonadRec<?,M>>
- Specified by:
pure
in interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>
- 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> ReaderT<R,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<R,M extends MonadRec<?,M>>
- Specified by:
fmap
in interfaceFunctor<R,M extends MonadRec<?,M>>
- Specified by:
fmap
in interfaceMonad<R,M extends MonadRec<?,M>>
- Specified by:
fmap
in interfaceMonadReader<R,M extends MonadRec<?,M>,A>
- Specified by:
fmap
in interfaceMonadRec<R,M extends MonadRec<?,M>>
- Specified by:
fmap
in interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>
- Type Parameters:
B
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- a functor over B (the new parameter type)
-
zip
public <B> ReaderT<R,M,B> zip(Applicative<Fn1<? super A,? extends B>,ReaderT<R,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<R,M extends MonadRec<?,M>>
- Specified by:
zip
in interfaceMonad<R,M extends MonadRec<?,M>>
- Specified by:
zip
in interfaceMonadReader<R,M extends MonadRec<?,M>,A>
- Specified by:
zip
in interfaceMonadRec<R,M extends MonadRec<?,M>>
- Specified by:
zip
in interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>
- Type Parameters:
B
- the resulting applicative parameter type- Parameters:
appFn
- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
public <B> Lazy<ReaderT<R,M,B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,ReaderT<R,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<R,M extends MonadRec<?,M>>
- Specified by:
lazyZip
in interfaceMonad<R,M extends MonadRec<?,M>>
- Specified by:
lazyZip
in interfaceMonadReader<R,M extends MonadRec<?,M>,A>
- Specified by:
lazyZip
in interfaceMonadRec<R,M extends MonadRec<?,M>>
- Specified by:
lazyZip
in interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>
- 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> ReaderT<R,M,B> discardL(Applicative<B,ReaderT<R,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<R,M extends MonadRec<?,M>>
- Specified by:
discardL
in interfaceMonad<R,M extends MonadRec<?,M>>
- Specified by:
discardL
in interfaceMonadReader<R,M extends MonadRec<?,M>,A>
- Specified by:
discardL
in interfaceMonadRec<R,M extends MonadRec<?,M>>
- Specified by:
discardL
in interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>
- Type Parameters:
B
- the type of the returned Applicative's parameter- Parameters:
appB
- the other Applicative- Returns:
- appB
-
discardR
public <B> ReaderT<R,M,A> discardR(Applicative<B,ReaderT<R,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<R,M extends MonadRec<?,M>>
- Specified by:
discardR
in interfaceMonad<R,M extends MonadRec<?,M>>
- Specified by:
discardR
in interfaceMonadReader<R,M extends MonadRec<?,M>,A>
- Specified by:
discardR
in interfaceMonadRec<R,M extends MonadRec<?,M>>
- Specified by:
discardR
in interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>
- Type Parameters:
B
- the type of appB's parameter- Parameters:
appB
- the other Applicative- Returns:
- this Applicative
-
diMap
public <Q,B> ReaderT<Q,M,B> diMap(Fn1<? super Q,? extends R> lFn, Fn1<? super A,? extends B> rFn)
Dually map contravariantly over the left parameter and covariantly over the right parameter. This is isomorphic todiMapL(lFn).diMapR(rFn)
.- Specified by:
diMap
in interfaceCartesian<R,M extends MonadRec<?,M>,A>
- Specified by:
diMap
in interfaceProfunctor<R,M extends MonadRec<?,M>,A>
- Type Parameters:
Q
- the new left parameter typeB
- the new right parameter type- Parameters:
lFn
- the left parameter mapping functionrFn
- the right parameter mapping function- Returns:
- a profunctor over Z (the new left parameter type) and C (the new right parameter type)
-
diMapL
public <Q> ReaderT<Q,M,A> diMapL(Fn1<? super Q,? extends R> fn)
Contravariantly map over the left parameter.- Specified by:
diMapL
in interfaceCartesian<R,M extends MonadRec<?,M>,A>
- Specified by:
diMapL
in interfaceProfunctor<R,M extends MonadRec<?,M>,A>
- Type Parameters:
Q
- the new left parameter type- Parameters:
fn
- the mapping function- Returns:
- a profunctor over Z (the new left parameter type) and C (the same right parameter type)
-
diMapR
public <B> ReaderT<R,M,B> diMapR(Fn1<? super A,? extends B> fn)
Covariantly map over the right parameter. For all profunctors that are also functors, it should hold thatdiMapR(f) == fmap(f)
.- Specified by:
diMapR
in interfaceCartesian<R,M extends MonadRec<?,M>,A>
- Specified by:
diMapR
in interfaceProfunctor<R,M extends MonadRec<?,M>,A>
- Type Parameters:
B
- the new right parameter type- Parameters:
fn
- the mapping function- Returns:
- a profunctor over A (the same left parameter type) and C (the new right parameter type)
-
contraMap
public <Q> ReaderT<Q,M,A> contraMap(Fn1<? super Q,? extends R> fn)
Contravariantly mapA <- B
.- Specified by:
contraMap
in interfaceCartesian<R,M extends MonadRec<?,M>,A>
- Specified by:
contraMap
in interfaceContravariant<R,M extends MonadRec<?,M>>
- Specified by:
contraMap
in interfaceProfunctor<R,M extends MonadRec<?,M>,A>
- Type Parameters:
Q
- the new parameter type- Parameters:
fn
- the mapping function- Returns:
- the mapped Contravariant functor instance
-
cartesian
public <C> ReaderT<Tuple2<C,R>,M,Tuple2<C,A>> cartesian()
Pair some typeC
to this profunctor's carrier types.
-
carry
public ReaderT<R,M,Tuple2<R,A>> carry()
Pair the covariantly-positioned carrier type with the contravariantly-positioned carrier type. This can be thought of as "carrying" or "inspecting" the left parameter.
-
ask
public static <R,M extends MonadRec<?,M>> ReaderT<R,M,R> ask(Pure<M> pureM)
Given aPure
ask will give you access to the input within the monadic embedding
-
readerT
public static <R,M extends MonadRec<?,M>,A> ReaderT<R,M,A> readerT(Fn1<? super R,? extends MonadRec<A,M>> fn)
-
pureReaderT
public static <R,M extends MonadRec<?,M>> Pure<ReaderT<R,M,?>> pureReaderT(Pure<M> pureM)
-
-