Resource

public class Resource<F, A> : ResourceOf<F, A> where F : Bracket

Resource models resource allocation and releasing. It is specially useful when multiple resources that depend on each other need to be acquired and later released in reverse order. Whn a resource is created, one can make use of the use method to run a computation with the resource. The finalizers are guaranteed to run afterwards in reverse order of acquisition.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ value: ResourceOf<F, A>) -> Resource<F, A>

    Parameters

    value

    Value in higher kinded form.

    Return Value

    Value casted to Resource.

  • Initializes a resource.

    Declaration

    Swift

    public static func from(
        acquire: @escaping () -> Kind<F, A>,
        release: @escaping (A, ExitCase<F.E>) -> Kind<F, ()>) -> Resource<F, A>

    Parameters

    acquire

    Function to acquire the resource.

    release

    Function to release the resource.

    Return Value

    A Resource that will run the provided functions to acquire and release it.

  • Uses the resource.

    Declaration

    Swift

    public func use<C>(_ f: @escaping (A) -> Kind<F, C>) -> Kind<F, C>

    Parameters

    f

    Function to use the resource.

    Return Value

    Result of using the resource.

  • Undocumented

    Declaration

    Swift

    public func combine(_ other: Resource<F, A>) -> Resource<F, A>
  • Undocumented

    Declaration

    Swift

    public static func empty() -> Resource<F, A>