WriterT

public final class WriterT<F, W, A> : WriterTOf<F, W, A>

WriterT transformer represents operations that accumulate values through a computation or effect, without reading them.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: WriterTOf<F, W, A>) -> WriterT<F, W, A>

    Parameters

    fa

    Value in the higher-kind form.

    Return Value

    Value cast to WriterT.

  • Initializes a WriterT.

    Declaration

    Swift

    public init(_ value: Kind<F, (W, A)>)

    Parameters

    value

    A pair of accumulator and value wrapped in an effect.

  • Provides the values wrapped in this WriterT

    Declaration

    Swift

    public var runT: Kind<F, (W, A)> { get }
  • Initializes a Writer.

    Declaration

    Swift

    public convenience init(_ value: (W, A))

    Parameters

    value

    A pair of accumulator and value.

  • Initializes a Writer.

    Declaration

    Swift

    public convenience init(_ w: W, _ a: A)

    Parameters

    w

    The accumulator initial value.

    a

    The initial value.

  • Provides the values wrapped in this Writer

    Declaration

    Swift

    public var run: (W, A) { get }
  • The first element of the pair.

    Declaration

    Swift

    public var first: W { get }
  • The second element of the pair.

    Declaration

    Swift

    public var second: A { get }
  • Adds an accumulated value to an effect.

    Declaration

    Swift

    public static func putT(_ fa: Kind<F, A>, _ w: W) -> WriterT<F, W, A>

    Parameters

    fa

    A value wrapped in an effect.

    w

    A value for the accumulator.

    Return Value

    A WriterT where the effect wraps the original value with the accumulator.

  • Obtains an effect with the result value.

    Declaration

    Swift

    public func content() -> Kind<F, A>

    Return Value

    Effect with the result value.

  • Obtains an effect with the accumulator value.

    Declaration

    Swift

    public func written() -> Kind<F, W>

    Return Value

    Effect with the accumulator value.

  • Lifts an effect to a WriterT using the empty value of the Monoid as the accumulator.

    Declaration

    Swift

    public static func valueT(_ fa: Kind<F, A>) -> WriterT<F, W, A>

    Parameters

    fa

    An effect.

    Return Value

    A WriterT where the effect wraps the original value with an empty accumulator.

  • Creates a WriterT from values for the result and accumulator.

    Declaration

    Swift

    public static func both(_ w: W, _ a: A) -> WriterT<F, W, A>

    Parameters

    w

    Initial value for the accumulator.

    a

    Initial value for the result.

    Return Value

    A WriterT wrapping the provided values in an effect.

  • Creates a WriterT from a tuple.

    Declaration

    Swift

    public static func fromTuple(_ z: (W, A)) -> WriterT<F, W, A>

    Parameters

    z

    A tuple where the first component is used for the accumulator and the second for the result value.

    Return Value

    A WriterT wrapping the provided values in an effect.

  • Creates a WriterT from values for the result and accumulator.

    Declaration

    Swift

    public static func put(_ a: A, _ w: W) -> WriterT<F, W, A>

    Parameters

    a

    Initial value for the result.

    w

    Initial value for the accumulator.

    Return Value

    A WriterT wrapping the provided values in an effect.

  • Lifts an effect using the accumulator value of this WriterT.

    Declaration

    Swift

    public func liftF<B>(_ fb: Kind<F, B>) -> WriterT<F, W, B>

    Parameters

    fb

    Effect to be lifted.

    Return Value

    A WriterT wrapping the value contained in the effect parameter and using the accumulator of this WriterT.

  • Creates a WriterT from an initial value for the result.

    Declaration

    Swift

    public static func value(_ a: A) -> WriterT<F, W, A>

    Parameters

    a

    Initial value for the result.

    Return Value

    A WriterT wrapping the provided value and using the empty value of the Monoid for the accumulator.

  • Transforms the accumulator and result values using a provided function.

    Declaration

    Swift

    public func transform<B, U>(_ f: @escaping ((W, A)) -> (U, B)) -> WriterT<F, U, B>

    Parameters

    f

    Transforming function.

    Return Value

    A WriterT where the original values have been transformed using the provided function.

  • Transforms the wrapped value using a provided function.

    Declaration

    Swift

    public func transformT<B, U>(_ f: @escaping (Kind<F, (W, A)>) -> Kind<F, (U, B)>) -> WriterT<F, U, B>

    Parameters

    f

    Transforming function.

    Return Value

    A WriterT where the original values have been transformed using the provided function.

  • Transforms the accumulator using the provided function.

    Declaration

    Swift

    public func mapAcc<U>(_ f: @escaping (W) -> U) -> WriterT<F, U, A>

    Parameters

    f

    Transforming function.

    Return Value

    A WriterT with the same result as the original one, and the transformed accumulator.

  • Transforms the accumulator and result values using two functions.

    Declaration

    Swift

    public func bimap<B, U>(_ g: @escaping (W) -> U, _ f: @escaping (A) -> B) -> WriterT<F, U, B>

    Parameters

    g

    Transforming function for the accumulator.

    f

    Transforming function for the result.

    Return Value

    A WriterT where the original values have been transformed using the provided functions.

  • Flatmaps the provided function to the nested tuple.

    Declaration

    Swift

    public func subflatMap<B>(_ f: @escaping (A) -> (W, B)) -> WriterT<F, W, B>

    Parameters

    f

    Function for the flatmap operation.

    Return Value

    Result of flatmapping the provided function to the nested values, wrapped in the effect.

  • Swaps the result and accumulator values.

    Declaration

    Swift

    public func swap() -> WriterT<F, A, W>

    Return Value

    A WriterT where the accumulator is the original result value and vice versa.

  • Runs this effect and pairs the result with the accumulator for a new result.

    Declaration

    Swift

    public func listen() -> WriterTOf<F, W, (W, A)>

    Return Value

    A WriterT where the result is paired with the accumulator.

  • Flatmaps a function that produces an effect and lifts it back to WriterT.

    Declaration

    Swift

    public func semiflatMap<B>(_ f: @escaping (A) -> Kind<F, B>) -> WriterT<F, W, B>

    Parameters

    f

    A function producing an effect.

    Return Value

    Result of flatmapping and lifting the function on this value.

  • Resets the accumulator to the empty value of the Monoid.

    Declaration

    Swift

    public func reset() -> WriterT<F, W, A>

    Return Value

    A WriterT value with an empty accumulator and the same result value.