pub struct WriterT<W, MKind: Kind1, A> {
pub run_writer_t: MKind::Of<(A, W)>,
/* private fields */
}Expand description
The WriterT monad transformer for Kind-encoded types.
WriterT<W, MKind, A> wraps an inner value MKind::Of<(A, W)>: the
produced value A paired with an accumulated monoidal log W. The value
is stored in run_writer_t.
§Type Parameters
Fields§
§run_writer_t: MKind::Of<(A, W)>The wrapped inner computation: MKind::Of<(A, W)> (value-then-log).
Implementations§
Source§impl<W, MKind: Kind1, A> WriterT<W, MKind, A>
impl<W, MKind: Kind1, A> WriterT<W, MKind, A>
Sourcepub fn eval_writer_t(self) -> MKind::Of<A>
pub fn eval_writer_t(self) -> MKind::Of<A>
Runs the computation and keeps only the produced value, discarding
the log: MKind::Of<A> (inner Functor, projecting fst).
Sourcepub fn exec_writer_t(self) -> MKind::Of<W>
pub fn exec_writer_t(self) -> MKind::Of<W>
Runs the computation and keeps only the accumulated log, discarding
the value: MKind::Of<W> (inner Functor, projecting snd).
Sourcepub fn listen(self) -> WriterT<W, MKind, (A, W)>
pub fn listen(self) -> WriterT<W, MKind, (A, W)>
Exposes the accumulated log alongside the value, leaving it in place —
the chainable method form of
<WriterTKind<W, MKind> as MonadWriter<W, A, MKind>>::listen(self).
The produced value becomes (A, W) and the log remains W.
§Example
use monadify::transformers::writer::{Writer, WriterTKind, MonadWriter};
use monadify::identity::{Identity, IdentityKind};
let w: Writer<String, ()> =
WriterTKind::<String, IdentityKind>::tell("xyz".to_string());
let Identity((((), exposed), log)) = w.listen().run_writer_t;
assert_eq!(exposed, "xyz");
assert_eq!(log, "xyz");Sourcepub fn censor<F>(self, f: F) -> Self
pub fn censor<F>(self, f: F) -> Self
Rewrites the log with f, leaving the value unchanged — the chainable
method form of
<WriterTKind<W, MKind> as MonadWriter<W, A, MKind>>::censor(f, self).
The result is (a, f(w)).
§Example
use monadify::transformers::writer::{Writer, WriterTKind, MonadWriter};
use monadify::identity::{Identity, IdentityKind};
let w: Writer<String, ()> =
WriterTKind::<String, IdentityKind>::tell("quiet".to_string());
let Identity(((), log)) = w.censor(|s: String| s.to_uppercase()).run_writer_t;
assert_eq!(log, "QUIET");