Class WriterT<W,M extends MonadRec<?,M>,A>
java.lang.Object
com.jnape.palatable.lambda.monad.transformer.builtin.WriterT<W,M,A>
- Type Parameters:
W
- the accumulation typeM
- themonadic embedding
A
- the result type
- All Implemented Interfaces:
Applicative<A,
,WriterT<W, M, ?>> Functor<A,
,WriterT<W, M, ?>> Monad<A,
,WriterT<W, M, ?>> MonadBase<M,
,A, WriterT<W, ?, ?>> MonadRec<A,
,WriterT<W, M, ?>> MonadWriter<W,
,A, WriterT<W, M, ?>> MonadT<M,
A, WriterT<W, M, ?>, WriterT<W, ?, ?>>
public final class WriterT<W,M extends MonadRec<?,M>,A>
extends Object
implements MonadWriter<W,A,WriterT<W,M,?>>, MonadT<M,A,WriterT<W,M,?>,WriterT<W,?,?>>
A
monad transformer
for Writer
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionUpdate the accumulated state.discardL
(Applicative<B, WriterT<W, M, ?>> appB) Sequence both thisApplicative
andappB
, discarding thisApplicative's
result and returningappB
.discardR
(Applicative<B, WriterT<W, M, ?>> appB) Sequence both thisApplicative
andappB
, discardingappB's
result and returning thisApplicative
.evalWriterT
(Monoid<W> monoid) Given aMonoid
for the accumulation, run the computation represented by thisWriterT
inside themonadic effect
, ignoring the resulting accumulation, yielding the value in isolation.execWriterT
(Monoid<W> monoid) Given aMonoid
for the accumulation, run the computation represented by thisWriterT
inside themonadic effect
, ignoring the value, yielding the accumulation in isolation.Chain dependent computations that may continue or short-circuit based on previous results.Covariantly transmute this functor's parameter using the given mapping function.Given alazy
instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.Map the accumulation into a value and pair it with the current output.pure
(B b) Lift the valueb
into this applicative functor.pureWriterT
(Pure<M> pureM) runWriterT
(Monoid<W> monoid) Given aMonoid
for the accumulation, run the computation represented by thisWriterT
inside themonadic effect
, accumulate the written output in terms of theMonoid
, and produce the accumulation and the result inside theMonad
.trampolineM
(Fn1<? super A, ? extends MonadRec<RecursiveResult<A, B>, WriterT<W, 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
-
pureM
-
writerFn
-
-
Constructor Details
-
WriterT
-
-
Method Details
-
runWriterT
Given aMonoid
for the accumulation, run the computation represented by thisWriterT
inside themonadic effect
, accumulate the written output in terms of theMonoid
, and produce the accumulation and the result inside theMonad
. -
evalWriterT
Given aMonoid
for the accumulation, run the computation represented by thisWriterT
inside themonadic effect
, ignoring the resulting accumulation, yielding the value in isolation. -
execWriterT
Given aMonoid
for the accumulation, run the computation represented by thisWriterT
inside themonadic effect
, ignoring the value, yielding the accumulation in isolation. -
listens
Map the accumulation into a value and pair it with the current output.- Specified by:
listens
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - Type Parameters:
B
- the mapped output- Parameters:
fn
- the mapping function- Returns:
- the updated
MonadWriter
-
censor
Update the accumulated state.- Specified by:
censor
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - Parameters:
fn
- the update function- Returns:
- the updated
MonadWriter
-
lift
- Specified by:
lift
in interfaceMonadBase<W,
M extends MonadRec<?, M>, A> - Specified by:
lift
in interfaceMonadT<M extends MonadRec<?,
M>, A, WriterT<W, M extends MonadRec<?, M>, ?>, WriterT<W, ?, ?>> - Type Parameters:
B
- theMonadRec
carrier typeN
- the argumentMonadRec
witness- Parameters:
mb
- the argumentMonadRec
- Returns:
- the new
MonadBase
-
trampolineM
public <B> WriterT<W,M, trampolineMB> (Fn1<? super A, ? extends MonadRec<RecursiveResult<A, B>, WriterT<W, 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.
-
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<W,
M extends MonadRec<?, M>> - Specified by:
fmap
in interfaceFunctor<W,
M extends MonadRec<?, M>> - Specified by:
fmap
in interfaceMonad<W,
M extends MonadRec<?, M>> - Specified by:
fmap
in interfaceMonadRec<W,
M extends MonadRec<?, M>> - Specified by:
fmap
in interfaceMonadT<M extends MonadRec<?,
M>, A, WriterT<W, M extends MonadRec<?, M>, ?>, WriterT<W, ?, ?>> - Specified by:
fmap
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - 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<W,
M extends MonadRec<?, M>> - Specified by:
pure
in interfaceMonad<W,
M extends MonadRec<?, M>> - Specified by:
pure
in interfaceMonadRec<W,
M extends MonadRec<?, M>> - Specified by:
pure
in interfaceMonadT<M extends MonadRec<?,
M>, A, WriterT<W, M extends MonadRec<?, M>, ?>, WriterT<W, ?, ?>> - Specified by:
pure
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - Type Parameters:
B
- the type of the returned applicative's parameter- Parameters:
b
- the value- Returns:
- an instance of this applicative over b
-
flatMap
Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMap
in interfaceMonad<W,
M extends MonadRec<?, M>> - Specified by:
flatMap
in interfaceMonadRec<W,
M extends MonadRec<?, M>> - Specified by:
flatMap
in interfaceMonadT<M extends MonadRec<?,
M>, A, WriterT<W, M extends MonadRec<?, M>, ?>, WriterT<W, ?, ?>> - Specified by:
flatMap
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - Type Parameters:
B
- the resulting monad parameter type- Parameters:
f
- the dependent computation over A- Returns:
- the new monad instance
-
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<W,
M extends MonadRec<?, M>> - Specified by:
zip
in interfaceMonad<W,
M extends MonadRec<?, M>> - Specified by:
zip
in interfaceMonadRec<W,
M extends MonadRec<?, M>> - Specified by:
zip
in interfaceMonadT<M extends MonadRec<?,
M>, A, WriterT<W, M extends MonadRec<?, M>, ?>, WriterT<W, ?, ?>> - Specified by:
zip
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - Type Parameters:
B
- the resulting applicative parameter type- Parameters:
appFn
- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
public <B> Lazy<WriterT<W,M, lazyZipB>> (Lazy<? extends Applicative<Fn1<? super A, ? extends B>, WriterT<W, 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<W,
M extends MonadRec<?, M>> - Specified by:
lazyZip
in interfaceMonad<W,
M extends MonadRec<?, M>> - Specified by:
lazyZip
in interfaceMonadRec<W,
M extends MonadRec<?, M>> - Specified by:
lazyZip
in interfaceMonadT<M extends MonadRec<?,
M>, A, WriterT<W, M extends MonadRec<?, M>, ?>, WriterT<W, ?, ?>> - Specified by:
lazyZip
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - Type Parameters:
B
- the resulting applicative parameter type- Parameters:
lazyAppFn
- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
-
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<W,
M extends MonadRec<?, M>> - Specified by:
discardL
in interfaceMonad<W,
M extends MonadRec<?, M>> - Specified by:
discardL
in interfaceMonadRec<W,
M extends MonadRec<?, M>> - Specified by:
discardL
in interfaceMonadT<M extends MonadRec<?,
M>, A, WriterT<W, M extends MonadRec<?, M>, ?>, WriterT<W, ?, ?>> - Specified by:
discardL
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - 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<W,
M extends MonadRec<?, M>> - Specified by:
discardR
in interfaceMonad<W,
M extends MonadRec<?, M>> - Specified by:
discardR
in interfaceMonadRec<W,
M extends MonadRec<?, M>> - Specified by:
discardR
in interfaceMonadT<M extends MonadRec<?,
M>, A, WriterT<W, M extends MonadRec<?, M>, ?>, WriterT<W, ?, ?>> - Specified by:
discardR
in interfaceMonadWriter<W,
M extends MonadRec<?, M>, A> - Type Parameters:
B
- the type of appB's parameter- Parameters:
appB
- the other Applicative- Returns:
- this Applicative
-
tell
-
listen
-
writerT
-
pureWriterT
-
liftWriterT
-