Bracket

public protocol Bracket : MonadError

Bracket models a generalized abstracted pattern of safe resource acquisition and release in the face of errors or interruptions.

  • A way to safely acquire a resource and release in the face of errors and cancellations. It uses ExitCase to distinguish between different exit cases when releasing the acquired resource.

    Declaration

    Swift

    static func bracketCase<A, B>(
        acquire fa: Kind<Self, A>,
        release: @escaping (A, ExitCase<Self.E>) -> Kind<Self, Void>,
        use: @escaping (A) throws -> Kind<Self, B>) -> Kind<Self, B>

    Parameters

    fa

    Computation to describe the acquisition of the resource.

    release

    Function to release the acquired resource.

    use

    Function to use the acquired resource.

    Return Value

    Computation describing the result of using the resource.

  • A way to safely acquire a resource and release in the face of errors and cancellations. It uses ExitCase to distinguish between different exit cases when releasing the acquired resource.

    Declaration

    Swift

    static func bracket<A, B>(
        acquire fa: Kind<Self, A>,
        release: @escaping (A) -> Kind<Self, Void>,
        use: @escaping (A) throws -> Kind<Self, B>) -> Kind<Self, B>

    Parameters

    fa

    Computation to describe the acquisition of the resource.

    release

    Function to release the acquired resource, ignoring the outcome of the release of the resource.

    use

    Function to use the acquired resource.

    Return Value

    Computation describing the result of using the resource.

  • uncancelable(_:) Extension method

    Forces a resource to be uncancelable even when an interruption happens.

    Declaration

    Swift

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

    Parameters

    fa

    Computation describing the acquisition of the resource.

    Return Value

    An uncancelable computation.

  • guarantee(_:finalizer:) Extension method

    Executes the given finalizer when the source is finished, either in success, error or cancelation.

    Declaration

    Swift

    static func guarantee<A>(
        _ fa: Kind<Self, A>,
        finalizer: Kind<Self, Void>) -> Kind<Self, A>

    Parameters

    fa

    Computation describing the acquisition of the resource.

    finalizer

    Finalizer function to be invoked when the resource is released.

    Return Value

    A computation describing the resouce that will invoke the finalizer when it is released.

  • Executes the given finalizer when the source is finished, either in success, error or cancelation, alowing to differentiate between exit conditions.

    Declaration

    Swift

    static func guaranteeCase<A>(
        _ fa: Kind<Self, A>,
        finalizer: @escaping (ExitCase<Self.E>) -> Kind<Self, Void>) -> Kind<Self, A>

    Parameters

    fa

    Computation describing the acquisition of the resource.

    finalizer

    Finalizer function to be invoked when the resource is released, distinguishing the exit case.

    Return Value

    A computation describing the resource that will invoke the finalizer when it is released.