com.jnape.palatable.lambda.monad.transformer.builtin

## 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 type
    `M` - the `monadic 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`.

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `WriterT<W,M,A>` | `censor(Fn1<? super W,? extends W> fn)` Update the accumulated state.
    `<B> WriterT<W,M,B>` | `discardL(Applicative<B,WriterT<W,M,?>> appB)` Sequence both this `Applicative` and `appB`, discarding this `Applicative's` result and returning `appB`.
    `<B> WriterT<W,M,A>` | `discardR(Applicative<B,WriterT<W,M,?>> appB)` Sequence both this `Applicative` and `appB`, discarding `appB's` result and returning this `Applicative`.
    `<B> WriterT<W,M,B>` | `flatMap(Fn1<? super A,? extends Monad<B,WriterT<W,M,?>>> f)` Chain dependent computations that may continue or short-circuit based on previous results.
    `<B> WriterT<W,M,B>` | `fmap(Fn1<? super A,? extends B> fn)` Covariantly transmute this functor's parameter using the given mapping function.
    `<B> Lazy<WriterT<W,M,B>>` | `lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,WriterT<W,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>> WriterT<W,N,B>` | `lift(MonadRec<B,N> mb)` Lift a new argument `MonadRec` into this `MonadBase`.
    `static <W> Lift<WriterT<W,?,?>>` | `liftWriterT()` `Lift` for `WriterT`.
    `static <W,M extends MonadRec<?,M>,A> WriterT<W,M,A>` | `listen(MonadRec<A,M> ma)` Lift a value embedded in a `Monad` into a `WriterT`.
    `<B> WriterT<W,M,Tuple2<A,B>>` | `listens(Fn1<? super W,? extends B> fn)` Map the accumulation into a value and pair it with the current output.
    `<B> WriterT<W,M,B>` | `pure(B b)` Lift the value `b` into this applicative functor.
    `static <W,M extends MonadRec<?,M>> Pure<WriterT<W,M,?>>` | `pureWriterT(Pure<M> pureM)` The canonical `Pure` instance for `WriterT`.
    `<MAW extends MonadRec<Tuple2<A,W>,M>> MAW` | `runWriterT(Monoid<W> monoid)` Given a `Monoid` for the accumulation, run the computation represented by this `WriterT` inside the `monadic effect`, accumulate the written output in terms of the `Monoid`, and produce the accumulation and the result inside the `Monad`.
    `static <W,M extends MonadRec<?,M>> WriterT<W,M,Unit>` | `tell(MonadRec<W,M> mw)` Lift an accumulation embedded in a `Monad` into a `WriterT`.
    `<B> WriterT<W,M,B>` | `trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,WriterT<W,M,?>>> fn)` Given some operation yielding a `RecursiveResult` inside this `MonadRec`, internally trampoline the operation until it yields a `termination` instruction.
    `static <W,M extends MonadRec<?,M>,A> WriterT<W,M,A>` | `writerT(MonadRec<Tuple2<A,W>,M> maw)` Lift a value and an accumulation embedded in a `Monad` into a `WriterT`.
    `<B> WriterT<W,M,B>` | `zip(Applicative<Fn1<? super A,? extends B>,WriterT<W,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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.jnape.palatable.lambda.monad.Monad

      `join`

    - ### Methods inherited from interface com.jnape.palatable.lambda.functor.Functor

      `coerce`

- - ### Method Detail

    - #### runWriterT

          public <MAW extends MonadRec<Tuple2<A,W>,M>> MAW runWriterT(Monoid<W> monoid)

      Given a `Monoid` for the accumulation, run the computation represented by this `WriterT` inside the `monadic effect`, accumulate the written output in terms of the `Monoid`, and produce the accumulation and the result inside the `Monad`.
      Type Parameters:
        `MAW` - the inferred `Monad` result
      Parameters:
        `monoid` - the accumulation `Monoid`
      Returns:
        the accumulation with the result

    - #### listens

          public <B> WriterT<W,M,Tuple2<A,B>> listens(Fn1<? super W,? extends B> fn)

      Map the accumulation into a value and pair it with the current output.
      Specified by:
        `listens` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Type Parameters:
        `B` - the mapped output
      Parameters:
        `fn` - the mapping function
      Returns:
        the updated `MonadWriter`

    - #### censor

          public WriterT<W,M,A> censor(Fn1<? super W,? extends W> fn)

      Update the accumulated state.
      Specified by:
        `censor` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Parameters:
        `fn` - the update function
      Returns:
        the updated `MonadWriter`

    - #### lift

          public <B,N extends MonadRec<?,N>> WriterT<W,N,B> lift(MonadRec<B,N> mb)

      Lift a new argument `MonadRec` into this `MonadBase`.
      Specified by:
        `lift` in interface `MonadBase<M extends MonadRec<?,M>,A,WriterT<W,?,?>>`
      Specified by:
        `lift` in interface `MonadT<M extends MonadRec<?,M>,A,WriterT<W,M extends MonadRec<?,M>,?>,WriterT<W,?,?>>`
      Type Parameters:
        `B` - the `MonadRec` carrier type
        `N` - the argument `MonadRec` witness
      Parameters:
        `mb` - the argument `MonadRec`
      Returns:
        the new `MonadBase`

    - #### trampolineM

          public <B> WriterT<W,M,B> trampolineM(Fn1<? super A,? extends MonadRec<RecursiveResult<A,B>,WriterT<W,M,?>>> fn)

      Given some operation yielding a `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.

      Specified by:
        `trampolineM` in interface `MonadRec<A,WriterT<W,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 {@link CoProduct2 coproduct} implementation`, `for an implementation leveraging an already stack-safe {@link Monad#flatMap(Fn1)}`, `for a {@link MonadT monad transformer} implementation`

    - #### fmap

          public <B> WriterT<W,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:
        `fmap` in interface `Applicative<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `fmap` in interface `Functor<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `fmap` in interface `Monad<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `fmap` in interface `MonadRec<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `fmap` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `fmap` in interface `MonadT<M extends MonadRec<?,M>,A,WriterT<W,M extends MonadRec<?,M>,?>,WriterT<W,?,?>>`
      Type Parameters:
        `B` - the new parameter type
      Parameters:
        `fn` - the mapping function
      Returns:
        a functor over B (the new parameter type)

    - #### pure

          public <B> WriterT<W,M,B> pure(B b)

      Lift the value `b` into this applicative functor.
      Specified by:
        `pure` in interface `Applicative<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `pure` in interface `Monad<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `pure` in interface `MonadRec<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `pure` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `pure` in interface `MonadT<M extends MonadRec<?,M>,A,WriterT<W,M extends MonadRec<?,M>,?>,WriterT<W,?,?>>`
      Type Parameters:
        `B` - the type of the returned applicative's parameter
      Parameters:
        `b` - the value
      Returns:
        an instance of this applicative over b

    - #### flatMap

          public <B> WriterT<W,M,B> flatMap(Fn1<? super A,? extends Monad<B,WriterT<W,M,?>>> f)

      Chain dependent computations that may continue or short-circuit based on previous results.
      Specified by:
        `flatMap` in interface `Monad<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `flatMap` in interface `MonadRec<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `flatMap` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `flatMap` in interface `MonadT<M extends MonadRec<?,M>,A,WriterT<W,M extends MonadRec<?,M>,?>,WriterT<W,?,?>>`
      Type Parameters:
        `B` - the resulting monad parameter type
      Parameters:
        `f` - the dependent computation over A
      Returns:
        the new monad instance

    - #### zip

          public <B> WriterT<W,M,B> zip(Applicative<Fn1<? super A,? extends B>,WriterT<W,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:
        `zip` in interface `Applicative<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `zip` in interface `Monad<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `zip` in interface `MonadRec<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `zip` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `zip` in interface `MonadT<M extends MonadRec<?,M>,A,WriterT<W,M extends MonadRec<?,M>,?>,WriterT<W,?,?>>`
      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,B>> lazyZip(Lazy<? extends Applicative<Fn1<? super A,? extends B>,WriterT<W,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. This is useful for applicatives that support lazy evaluation and early termination.
      Specified by:
        `lazyZip` in interface `Applicative<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `lazyZip` in interface `Monad<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `lazyZip` in interface `MonadRec<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `lazyZip` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `lazyZip` in interface `MonadT<M extends MonadRec<?,M>,A,WriterT<W,M extends MonadRec<?,M>,?>,WriterT<W,?,?>>`
      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> WriterT<W,M,B> discardL(Applicative<B,WriterT<W,M,?>> appB)

      Sequence both this `Applicative` and `appB`, discarding this `Applicative's` result and returning `appB`. This is generally useful for sequentially performing side-effects.
      Specified by:
        `discardL` in interface `Applicative<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `discardL` in interface `Monad<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `discardL` in interface `MonadRec<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `discardL` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `discardL` in interface `MonadT<M extends MonadRec<?,M>,A,WriterT<W,M extends MonadRec<?,M>,?>,WriterT<W,?,?>>`
      Type Parameters:
        `B` - the type of the returned Applicative's parameter
      Parameters:
        `appB` - the other Applicative
      Returns:
        appB

    - #### discardR

          public <B> WriterT<W,M,A> discardR(Applicative<B,WriterT<W,M,?>> appB)

      Sequence both this `Applicative` and `appB`, discarding `appB's` result and returning this `Applicative`. This is generally useful for sequentially performing side-effects.
      Specified by:
        `discardR` in interface `Applicative<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `discardR` in interface `Monad<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `discardR` in interface `MonadRec<A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `discardR` in interface `MonadWriter<W,A,WriterT<W,M extends MonadRec<?,M>,?>>`
      Specified by:
        `discardR` in interface `MonadT<M extends MonadRec<?,M>,A,WriterT<W,M extends MonadRec<?,M>,?>,WriterT<W,?,?>>`
      Type Parameters:
        `B` - the type of appB's parameter
      Parameters:
        `appB` - the other Applicative
      Returns:
        this Applicative

    - #### tell

          public static <W,M extends MonadRec<?,M>> WriterT<W,M,Unit> tell(MonadRec<W,M> mw)

      Lift an accumulation embedded in a `Monad` into a `WriterT`.
      Type Parameters:
        `W` - the accumulation type
        `M` - the `Monad` type
      Parameters:
        `mw` - the accumulation inside a `Monad`
      Returns:
        the `WriterT`

    - #### listen

          public static <W,M extends MonadRec<?,M>,A> WriterT<W,M,A> listen(MonadRec<A,M> ma)

      Lift a value embedded in a `Monad` into a `WriterT`.
      Type Parameters:
        `W` - the accumulation type
        `M` - the `Monad` type
        `A` - the value type
      Parameters:
        `ma` - the value inside a `Monad`
      Returns:
        the `WriterT`

    - #### writerT

          public static <W,M extends MonadRec<?,M>,A> WriterT<W,M,A> writerT(MonadRec<Tuple2<A,W>,M> maw)

      Lift a value and an accumulation embedded in a `Monad` into a `WriterT`.
      Type Parameters:
        `W` - the accumulation type
        `M` - the `Monad` type
        `A` - the value type
      Parameters:
        `maw` - the value and accumulation inside a `Monad`
      Returns:
        the `WriterT`

    - #### pureWriterT

          public static <W,M extends MonadRec<?,M>> Pure<WriterT<W,M,?>> pureWriterT(Pure<M> pureM)

      The canonical `Pure` instance for `WriterT`.
      Type Parameters:
        `W` - the accumulation type
        `M` - the argument `Monad` witness
      Parameters:
        `pureM` - the argument `Monad` `Pure`
      Returns:
        the `Pure` instance

    - #### liftWriterT

          public static <W> Lift<WriterT<W,?,?>> liftWriterT()

      `Lift` for `WriterT`.
      Type Parameters:
        `W` - the accumulated type
      Returns:
        the `Monad` lifted into `WriterT`