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 returnedMonadRecA- 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 betweenReaderTinstances 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 aPureask 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 typeCto 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 thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.<B> ReaderT<R,M,A>discardR(Applicative<B,ReaderT<R,M,?>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult 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 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>>
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'senvironment 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 valuebinto 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 aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.<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 betweenReaderTinstances 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'senvironment after reading it but before running the effect.- Specified by:
localin interfaceMonadReader<R,M extends MonadRec<?,M>,A>- Parameters:
fn- the modification function- Returns:
- the
MonadReaderwith a modified environment
-
lift
public <B,N extends MonadRec<?,N>> ReaderT<R,N,B> lift(MonadRec<B,N> mb)
- Specified by:
liftin interfaceMonadBase<R,M extends MonadRec<?,M>,A>- Specified by:
liftin interfaceMonadT<M extends MonadRec<?,M>,A,ReaderT<R,M extends MonadRec<?,M>,?>,ReaderT<R,?,?>>- Type Parameters:
B- theMonadReccarrier typeN- the argumentMonadRecwitness- 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:
flatMapin interfaceMonad<R,M extends MonadRec<?,M>>- Specified by:
flatMapin interfaceMonadReader<R,M extends MonadRec<?,M>,A>- Specified by:
flatMapin interfaceMonadRec<R,M extends MonadRec<?,M>>- Specified by:
flatMapin 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 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<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 valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<R,M extends MonadRec<?,M>>- Specified by:
purein interfaceMonad<R,M extends MonadRec<?,M>>- Specified by:
purein interfaceMonadReader<R,M extends MonadRec<?,M>,A>- Specified by:
purein interfaceMonadRec<R,M extends MonadRec<?,M>>- Specified by:
purein 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:
fmapin interfaceApplicative<R,M extends MonadRec<?,M>>- Specified by:
fmapin interfaceFunctor<R,M extends MonadRec<?,M>>- Specified by:
fmapin interfaceMonad<R,M extends MonadRec<?,M>>- Specified by:
fmapin interfaceMonadReader<R,M extends MonadRec<?,M>,A>- Specified by:
fmapin interfaceMonadRec<R,M extends MonadRec<?,M>>- Specified by:
fmapin 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:
zipin interfaceApplicative<R,M extends MonadRec<?,M>>- Specified by:
zipin interfaceMonad<R,M extends MonadRec<?,M>>- Specified by:
zipin interfaceMonadReader<R,M extends MonadRec<?,M>,A>- Specified by:
zipin interfaceMonadRec<R,M extends MonadRec<?,M>>- Specified by:
zipin 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 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<R,M extends MonadRec<?,M>>- Specified by:
lazyZipin interfaceMonad<R,M extends MonadRec<?,M>>- Specified by:
lazyZipin interfaceMonadReader<R,M extends MonadRec<?,M>,A>- Specified by:
lazyZipin interfaceMonadRec<R,M extends MonadRec<?,M>>- Specified by:
lazyZipin 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 thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.- Specified by:
discardLin interfaceApplicative<R,M extends MonadRec<?,M>>- Specified by:
discardLin interfaceMonad<R,M extends MonadRec<?,M>>- Specified by:
discardLin interfaceMonadReader<R,M extends MonadRec<?,M>,A>- Specified by:
discardLin interfaceMonadRec<R,M extends MonadRec<?,M>>- Specified by:
discardLin 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 thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<R,M extends MonadRec<?,M>>- Specified by:
discardRin interfaceMonad<R,M extends MonadRec<?,M>>- Specified by:
discardRin interfaceMonadReader<R,M extends MonadRec<?,M>,A>- Specified by:
discardRin interfaceMonadRec<R,M extends MonadRec<?,M>>- Specified by:
discardRin 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:
diMapin interfaceCartesian<R,M extends MonadRec<?,M>,A>- Specified by:
diMapin 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:
diMapLin interfaceCartesian<R,M extends MonadRec<?,M>,A>- Specified by:
diMapLin 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:
diMapRin interfaceCartesian<R,M extends MonadRec<?,M>,A>- Specified by:
diMapRin 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:
contraMapin interfaceCartesian<R,M extends MonadRec<?,M>,A>- Specified by:
contraMapin interfaceContravariant<R,M extends MonadRec<?,M>>- Specified by:
contraMapin 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 typeCto 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 aPureask 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)
-
-