W
- the accumulation typeA
- the value typepublic final class Writer<W,A> extends Object implements MonadWriter<W,A,Writer<W,?>>, MonadRec<A,Writer<W,?>>
Modifier and Type | Method and Description |
---|---|
Writer<W,A> |
censor(Fn1<? super W,? extends W> fn)
Update the accumulated state.
|
<B> Writer<W,B> |
discardL(Applicative<B,Writer<W,?>> appB)
Sequence both this
Applicative and appB , discarding this Applicative's
result and returning appB . |
<B> Writer<W,A> |
discardR(Applicative<B,Writer<W,?>> appB)
Sequence both this
Applicative and appB , discarding appB's result and
returning this Applicative . |
<B> Writer<W,B> |
flatMap(Fn1<? super A,? extends Monad<B,Writer<W,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.
|
<B> Writer<W,B> |
fmap(Fn1<? super A,? extends B> fn)
Covariantly transmute this functor's parameter using the given mapping function.
|
<B> Lazy<Writer<W,B>> |
lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,Writer<W,?>>> 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. |
static <W,A> Writer<W,A> |
listen(A a)
Construct a
Writer from a value. |
<B> Writer<W,Tuple2<A,B>> |
listens(Fn1<? super W,? extends B> fn)
Map the accumulation into a value and pair it with the current output.
|
<B> Writer<W,B> |
pure(B b)
Lift the value
b into this applicative functor. |
static <W> Pure<Writer<W,?>> |
pureWriter()
|
Tuple2<A,W> |
runWriter(Monoid<W> monoid)
|
static <W> Writer<W,Unit> |
tell(W w)
Construct a
Writer from an accumulation. |
<B> Writer<W,B> |
trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,Writer<W,?>>> fn)
Given some operation yielding a
RecursiveResult inside this MonadRec , internally trampoline the
operation until it yields a termination instruction. |
static <W,A> Writer<W,A> |
writer(Tuple2<A,W> aw)
Construct a
Writer from an accumulation and a value. |
<B> Writer<W,B> |
zip(Applicative<Fn1<? super A,? extends B>,Writer<W,?>> 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 Tuple2<A,W> runWriter(Monoid<W> monoid)
Monoid
for the accumulation, run the computation represented by this Writer
, accumulate
the written output in terms of the Monoid
, and produce the accumulation and the value.monoid
- the accumulation Monoid
public <B> Writer<W,Tuple2<A,B>> listens(Fn1<? super W,? extends B> fn)
listens
in interface MonadWriter<W,A,Writer<W,?>>
B
- the mapped outputfn
- the mapping functionMonadWriter
public Writer<W,A> censor(Fn1<? super W,? extends W> fn)
censor
in interface MonadWriter<W,A,Writer<W,?>>
fn
- the update functionMonadWriter
public <B> Writer<W,B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,Writer<W,?>>> 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,Writer<W,?>>
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 <B> Writer<W,B> flatMap(Fn1<? super A,? extends Monad<B,Writer<W,?>>> f)
flatMap
in interface Monad<A,Writer<W,?>>
flatMap
in interface MonadRec<A,Writer<W,?>>
flatMap
in interface MonadWriter<W,A,Writer<W,?>>
B
- the resulting monad parameter typef
- the dependent computation over Apublic <B> Writer<W,B> pure(B b)
b
into this applicative functor.pure
in interface Applicative<A,Writer<W,?>>
pure
in interface Monad<A,Writer<W,?>>
pure
in interface MonadRec<A,Writer<W,?>>
pure
in interface MonadWriter<W,A,Writer<W,?>>
B
- the type of the returned applicative's parameterb
- the valuepublic <B> Writer<W,B> fmap(Fn1<? super A,? extends B> fn)
fmap
in interface Applicative<A,Writer<W,?>>
fmap
in interface Functor<A,Writer<W,?>>
fmap
in interface Monad<A,Writer<W,?>>
fmap
in interface MonadRec<A,Writer<W,?>>
fmap
in interface MonadWriter<W,A,Writer<W,?>>
B
- the new parameter typefn
- the mapping functionpublic <B> Writer<W,B> zip(Applicative<Fn1<? super A,? extends B>,Writer<W,?>> appFn)
zip
in interface Applicative<A,Writer<W,?>>
zip
in interface Monad<A,Writer<W,?>>
zip
in interface MonadRec<A,Writer<W,?>>
zip
in interface MonadWriter<W,A,Writer<W,?>>
B
- the resulting applicative parameter typeappFn
- the other applicative instancepublic <B> Lazy<Writer<W,B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,Writer<W,?>>> 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,Writer<W,?>>
lazyZip
in interface Monad<A,Writer<W,?>>
lazyZip
in interface MonadRec<A,Writer<W,?>>
lazyZip
in interface MonadWriter<W,A,Writer<W,?>>
B
- the resulting applicative parameter typelazyAppFn
- the lazy other applicative instanceMaybe
,
Either
public <B> Writer<W,B> discardL(Applicative<B,Writer<W,?>> 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,Writer<W,?>>
discardL
in interface Monad<A,Writer<W,?>>
discardL
in interface MonadRec<A,Writer<W,?>>
discardL
in interface MonadWriter<W,A,Writer<W,?>>
B
- the type of the returned Applicative's parameterappB
- the other Applicativepublic <B> Writer<W,A> discardR(Applicative<B,Writer<W,?>> 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,Writer<W,?>>
discardR
in interface Monad<A,Writer<W,?>>
discardR
in interface MonadRec<A,Writer<W,?>>
discardR
in interface MonadWriter<W,A,Writer<W,?>>
B
- the type of appB's parameterappB
- the other Applicativepublic static <W> Writer<W,Unit> tell(W w)
Writer
from an accumulation.W
- the accumulation typeWriter
public static <W,A> Writer<W,A> listen(A a)
Writer
from a value.W
- the accumulation typeA
- the value typeWriter
public static <W,A> Writer<W,A> writer(Tuple2<A,W> aw)
Writer
from an accumulation and a value.W
- the accumulation typeA
- the value typeWriterT