MonadWriter

public protocol MonadWriter : Monad

A MonadWriter is a Monad with the ability to produce a stream of data in addition to the computed values.

  • Type of the side stream of data produced by this monad

    Declaration

    Swift

    associatedtype W
  • Embeds a writer action.

    Declaration

    Swift

    static func writer<A>(_ aw: (W, A)) -> Kind<Self, A>

    Parameters

    aw

    A tupe of the writer type and a value.

    Return Value

    The writer action embedded in the context implementing this instance.

  • Adds the side stream of data to the result of a computation.

    Declaration

    Swift

    static func listen<A>(_ fa: Kind<Self, A>) -> Kind<Self, (W, A)>

    Parameters

    fa

    A computation.

    Return Value

    The result of the computation paired with the side stream of data.

  • Performs a computation and transforms the side stream of data.

    Declaration

    Swift

    static func pass<A>(_ fa: Kind<Self, ((W) -> W, A)>) -> Kind<Self, A>

    Parameters

    fa

    A computation that transform the stream of data.

    Return Value

    Result of the computation.

  • tell(_:) Extension method

    Produces a new value of the side stream of data.

    Declaration

    Swift

    public static func tell(_ w: W) -> Kind<Self, ()>

    Parameters

    w

    New value.

    Return Value

    Unit.

  • listens(_:_:) Extension method

    Performs a computation and transforms the side stream of data, pairing it with the result of the computation.

    Declaration

    Swift

    public static func listens<A, B>(_ fa: Kind<Self, A>, _ f: @escaping (W) -> B) -> Kind<Self, (B, A)>

    Parameters

    fa

    A computation.

    f

    A function to transform the side stream of data.

    Return Value

    A tuple of the transformation of the side stream and the result of the computation.

  • censor(_:_:) Extension method

    Transforms the side stream of data of a given computation.

    Declaration

    Swift

    public static func censor<A>(_ fa: Kind<Self, A>, _ f: @escaping (W) -> W) -> Kind<Self, A>

    Parameters

    fa

    A computation.

    f

    Transforming function.

    Return Value

    A computation with the same result as the provided one, with the transformed side stream of data.