MonadError

public protocol MonadError : ApplicativeError, Monad

A MonadError has the same capabilities as a Monad and an ApplicativeError.

  • ensure(_:_:_:) Extension method

    Checks if the value of a computation matches a predicate, raising an error if not.

    Declaration

    Swift

    static func ensure<A>(
        _ fa: Kind<Self, A>,
        _ error: @escaping () -> E,
        _ predicate: @escaping (A) -> Bool) -> Kind<Self, A>

    Parameters

    fa

    A computation in the context implementing this instance.

    error

    A function that produces an error of the type this instance is able to handle.

    predicate

    A boolean predicate to test the value of the computation.

    Return Value

    A value or an error in the context implementing this instance.

  • flatTapError(_:_:) Extension method

    Applies a monadic function to an effect discarding the output.

    Declaration

    Swift

    static func flatTapError<A, B>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (E) -> Kind<Self, B>) -> Kind<Self, A>

    Parameters

    fa

    A computation.

    f

    A monadic function which result will be discarded.

    Return Value

    A computation with the effect of the initial computation.