S
- the state typeM
- the monadic embedding
A
- the result typepublic final class StateT<S,M extends MonadRec<?,M>,A> extends Object implements MonadT<M,A,StateT<S,M,?>,StateT<S,?,?>>, MonadReader<S,A,StateT<S,M,?>>, MonadWriter<S,A,StateT<S,M,?>>
State
monad transformer
.State
Modifier and Type | Method and Description |
---|---|
StateT<S,M,A> |
censor(Fn1<? super S,? extends S> fn)
Update the accumulated state.
|
<B> StateT<S,M,B> |
discardL(Applicative<B,StateT<S,M,?>> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
<B> StateT<S,M,A> |
discardR(Applicative<B,StateT<S,M,?>> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
<MA extends Monad<A,M>> |
evalT(S s)
Run the stateful computation embedded in the
Monad , returning the result. |
<MS extends Monad<S,M>> |
execT(S s)
Run the stateful computation embedded in the
Monad , returning the final state. |
<B> StateT<S,M,B> |
flatMap(Fn1<? super A,? extends Monad<B,StateT<S,M,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
|
<B> StateT<S,M,B> |
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.
|
static <A,M extends MonadRec<?,M>> |
get(Pure<M> pureM)
|
static <S,M extends MonadRec<?,M>,A> |
gets(Fn1<? super S,? extends MonadRec<A,M>> fn)
Given a function that produces a value inside a
monadic effect from a state, produce a
StateT that simply passes its state to the function and applies it. |
<B> Lazy<StateT<S,M,B>> |
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,StateT<S,M,?>>> lazyAppFn)
Given a
lazy 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>> |
lift(MonadRec<B,N> mb)
|
static <S> Lift<StateT<S,?,?>> |
liftStateT()
|
<B> StateT<S,M,Tuple2<A,B>> |
listens(Fn1<? super S,? extends B> fn)
Map the accumulation into a value and pair it with the current output.
|
StateT<S,M,A> |
local(Fn1<? super S,? extends S> fn)
Modify this
MonadReader's environment after reading it but before running the effect. |
<N extends MonadRec<?,N>,B> |
mapStateT(Fn1<? super MonadRec<Tuple2<A,S>,M>,? extends MonadRec<Tuple2<B,S>,N>> fn)
Map both the result and the final state to a new result and final state inside the
Monad . |
static <S,M extends MonadRec<?,M>> |
modify(Fn1<? super S,? extends MonadRec<S,M>> updateFn)
|
<B> StateT<S,M,B> |
pure(B b)
Lift the value
b into this applicative functor. |
static <S,M extends MonadRec<?,M>> |
pureStateT(Pure<M> pureM)
|
static <S,M extends MonadRec<?,M>> |
put(MonadRec<S,M> ms)
Lift a
monadic state into StateT . |
<MAS extends MonadRec<Tuple2<A,S>,M>> |
runStateT(S s)
|
static <S,M extends MonadRec<?,M>,A> |
stateT(Fn1<? super S,? extends MonadRec<Tuple2<A,S>,M>> stateFn)
Lift a state-sensitive
monadically embedded computation into StateT . |
static <S,M extends MonadRec<?,M>,A> |
stateT(MonadRec<A,M> ma)
Lift a
monadic value into StateT . |
<B> StateT<S,M,B> |
trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,StateT<S,M,?>>> fn)
Given some operation yielding a
RecursiveResult inside this MonadRec , internally trampoline the
operation until it yields a termination instruction. |
StateT<S,M,A> |
withStateT(Fn1<? super S,? extends MonadRec<S,M>> fn)
Map the final state to a new final state inside the same
monadic effect using the provided
function. |
<B> StateT<S,M,B> |
zip(Applicative<Fn1<? super A,? extends B>,StateT<S,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.
|
public <MA extends Monad<A,M>> MA evalT(S s)
Monad
, returning the result.MA
- the inferred Monad
results
- the initial statepublic <MS extends Monad<S,M>> MS execT(S s)
Monad
, returning the final state.MS
- the inferred Monad
results
- the initial statepublic <N extends MonadRec<?,N>,B> StateT<S,N,B> mapStateT(Fn1<? super MonadRec<Tuple2<A,S>,M>,? extends MonadRec<Tuple2<B,S>,N>> fn)
Monad
.N
- the new monadic embedding
for this StateT
B
- the new state typefn
- the mapping functionStateT
public StateT<S,M,A> withStateT(Fn1<? super S,? extends MonadRec<S,M>> fn)
monadic effect
using the provided
function.fn
- the state-mapping functionStateT
public <B> StateT<S,M,Tuple2<A,B>> listens(Fn1<? super S,? extends B> fn)
listens
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
B
- the mapped outputfn
- the mapping functionMonadWriter
public StateT<S,M,A> censor(Fn1<? super S,? extends S> fn)
censor
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
fn
- the update functionMonadWriter
public StateT<S,M,A> local(Fn1<? super S,? extends S> fn)
MonadReader's
environment after reading it but before running the effect.local
in interface MonadReader<S,A,StateT<S,M extends MonadRec<?,M>,?>>
fn
- the modification functionMonadReader
with a modified environmentpublic <B> StateT<S,M,B> flatMap(Fn1<? super A,? extends Monad<B,StateT<S,M,?>>> f)
flatMap
in interface Monad<A,StateT<S,M extends MonadRec<?,M>,?>>
flatMap
in interface MonadReader<S,A,StateT<S,M extends MonadRec<?,M>,?>>
flatMap
in interface MonadRec<A,StateT<S,M extends MonadRec<?,M>,?>>
flatMap
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
flatMap
in interface MonadT<M extends MonadRec<?,M>,A,StateT<S,M extends MonadRec<?,M>,?>,StateT<S,?,?>>
B
- the resulting monad parameter typef
- the dependent computation over Apublic <B> StateT<S,M,B> pure(B b)
b
into this applicative functor.pure
in interface Applicative<A,StateT<S,M extends MonadRec<?,M>,?>>
pure
in interface Monad<A,StateT<S,M extends MonadRec<?,M>,?>>
pure
in interface MonadReader<S,A,StateT<S,M extends MonadRec<?,M>,?>>
pure
in interface MonadRec<A,StateT<S,M extends MonadRec<?,M>,?>>
pure
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
pure
in interface MonadT<M extends MonadRec<?,M>,A,StateT<S,M extends MonadRec<?,M>,?>,StateT<S,?,?>>
B
- the type of the returned applicative's parameterb
- the valuepublic <B> StateT<S,M,B> fmap(Fn1<? super A,? extends B> fn)
fmap
in interface Applicative<A,StateT<S,M extends MonadRec<?,M>,?>>
fmap
in interface Functor<A,StateT<S,M extends MonadRec<?,M>,?>>
fmap
in interface Monad<A,StateT<S,M extends MonadRec<?,M>,?>>
fmap
in interface MonadReader<S,A,StateT<S,M extends MonadRec<?,M>,?>>
fmap
in interface MonadRec<A,StateT<S,M extends MonadRec<?,M>,?>>
fmap
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
fmap
in interface MonadT<M extends MonadRec<?,M>,A,StateT<S,M extends MonadRec<?,M>,?>,StateT<S,?,?>>
B
- the new parameter typefn
- the mapping functionpublic <B> StateT<S,M,B> zip(Applicative<Fn1<? super A,? extends B>,StateT<S,M,?>> appFn)
zip
in interface Applicative<A,StateT<S,M extends MonadRec<?,M>,?>>
zip
in interface Monad<A,StateT<S,M extends MonadRec<?,M>,?>>
zip
in interface MonadReader<S,A,StateT<S,M extends MonadRec<?,M>,?>>
zip
in interface MonadRec<A,StateT<S,M extends MonadRec<?,M>,?>>
zip
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
zip
in interface MonadT<M extends MonadRec<?,M>,A,StateT<S,M extends MonadRec<?,M>,?>,StateT<S,?,?>>
B
- the resulting applicative parameter typeappFn
- the other applicative instancepublic <B> Lazy<StateT<S,M,B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,StateT<S,M,?>>> lazyAppFn)
lazy
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.lazyZip
in interface Applicative<A,StateT<S,M extends MonadRec<?,M>,?>>
lazyZip
in interface Monad<A,StateT<S,M extends MonadRec<?,M>,?>>
lazyZip
in interface MonadReader<S,A,StateT<S,M extends MonadRec<?,M>,?>>
lazyZip
in interface MonadRec<A,StateT<S,M extends MonadRec<?,M>,?>>
lazyZip
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
lazyZip
in interface MonadT<M extends MonadRec<?,M>,A,StateT<S,M extends MonadRec<?,M>,?>,StateT<S,?,?>>
B
- the resulting applicative parameter typelazyAppFn
- the lazy other applicative instanceMaybe
,
Either
public <B> StateT<S,M,B> discardL(Applicative<B,StateT<S,M,?>> appB)
Applicative
and appB
, discarding this Applicative's
result and returning appB
. This is generally useful for sequentially performing side-effects.discardL
in interface Applicative<A,StateT<S,M extends MonadRec<?,M>,?>>
discardL
in interface Monad<A,StateT<S,M extends MonadRec<?,M>,?>>
discardL
in interface MonadReader<S,A,StateT<S,M extends MonadRec<?,M>,?>>
discardL
in interface MonadRec<A,StateT<S,M extends MonadRec<?,M>,?>>
discardL
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
discardL
in interface MonadT<M extends MonadRec<?,M>,A,StateT<S,M extends MonadRec<?,M>,?>,StateT<S,?,?>>
B
- the type of the returned Applicative's parameterappB
- the other Applicativepublic <B> StateT<S,M,A> discardR(Applicative<B,StateT<S,M,?>> appB)
Applicative
and appB
, discarding appB's
result and
returning this Applicative
. This is generally useful for sequentially performing side-effects.discardR
in interface Applicative<A,StateT<S,M extends MonadRec<?,M>,?>>
discardR
in interface Monad<A,StateT<S,M extends MonadRec<?,M>,?>>
discardR
in interface MonadReader<S,A,StateT<S,M extends MonadRec<?,M>,?>>
discardR
in interface MonadRec<A,StateT<S,M extends MonadRec<?,M>,?>>
discardR
in interface MonadWriter<S,A,StateT<S,M extends MonadRec<?,M>,?>>
discardR
in interface MonadT<M extends MonadRec<?,M>,A,StateT<S,M extends MonadRec<?,M>,?>,StateT<S,?,?>>
B
- the type of appB's parameterappB
- the other Applicativepublic <B,N extends MonadRec<?,N>> StateT<S,N,B> lift(MonadRec<B,N> mb)
lift
in interface MonadBase<M extends MonadRec<?,M>,A,StateT<S,?,?>>
lift
in interface MonadT<M extends MonadRec<?,M>,A,StateT<S,M extends MonadRec<?,M>,?>,StateT<S,?,?>>
B
- the MonadRec
carrier typeN
- the argument MonadRec
witnessmb
- the argument MonadRec
MonadBase
public <B> StateT<S,M,B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,StateT<S,M,?>>> fn)
RecursiveResult
inside this MonadRec
, internally trampoline the
operation until it yields a termination
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.
trampolineM
in interface MonadRec<A,StateT<S,M extends MonadRec<?,M>,?>>
B
- the ultimate resulting carrier typefn
- the function to internally trampolineMonadRec
for a basic implementation
,
for a {@link CoProduct2 coproduct} implementation
,
for an implementation leveraging an already stack-safe {@link Monad#flatMap(Fn1)}
,
for a {@link MonadT monad transformer} implementation
public static <S,M extends MonadRec<?,M>,A> StateT<S,M,A> gets(Fn1<? super S,? extends MonadRec<A,M>> fn)
monadic effect
from a state, produce a
StateT
that simply passes its state to the function and applies it.public static <S,M extends MonadRec<?,M>> StateT<S,M,Unit> modify(Fn1<? super S,? extends MonadRec<S,M>> updateFn)
public static <S,M extends MonadRec<?,M>> StateT<S,M,Unit> put(MonadRec<S,M> ms)
monadic state
into StateT
.public static <S,M extends MonadRec<?,M>,A> StateT<S,M,A> stateT(MonadRec<A,M> ma)
monadic value
into StateT
.public static <S,M extends MonadRec<?,M>,A> StateT<S,M,A> stateT(Fn1<? super S,? extends MonadRec<Tuple2<A,S>,M>> stateFn)
monadically embedded
computation into StateT
.