arrow-fx / arrow.fx.typeclasses / Bracket

Bracket

interface Bracket<F, E> : MonadError<F, E>

Extension of MonadError exposing the bracket operation, a generalized abstracted pattern of safe resource acquisition and release in the face of errors or interruption.

Define The functions receiver here (Kind<F, A>) would stand for the “acquireParam”, and stands for an action that “acquires” some expensive resource, that needs to be used and then discarded.

Define use is the action that uses the newly allocated resource and that will provide the final result.

Functions

bracket Meant for specifying tasks with safe resource acquisition and release in the face of errors and interruption. It would be the the equivalent of try/catch/finally statements in mainstream imperative languages for resource acquisition and release.open fun <A, B> Kind<F, A>.bracket(release: (A) -> Kind<F, Unit>, use: (A) -> Kind<F, B>): Kind<F, B>
bracketCase A way to safely acquire a resource and release in the face of errors and cancellation. It uses ExitCase to distinguish between different exit cases when releasing the acquired resource.abstract fun <A, B> Kind<F, A>.bracketCase(release: (A, ExitCase<E>) -> Kind<F, Unit>, use: (A) -> Kind<F, B>): Kind<F, B>
guarantee Executes the given finalizer when the source is finished, either in success or in error, or if canceled.open fun <A> Kind<F, A>.guarantee(finalizer: Kind<F, Unit>): Kind<F, A>
guaranteeCase Executes the given finalizer when the source is finished, either in success or in error, or if canceled, allowing for differentiating between exit conditions. That’s thanks to the ExitCase argument of the finalizer.open fun <A> Kind<F, A>.guaranteeCase(finalizer: (ExitCase<E>) -> Kind<F, Unit>): Kind<F, A>
onCancel Executes the given finalizer when the source is canceled, allowing registering a cancellation token.open fun <A> Kind<F, A>.onCancel(finalizer: Kind<F, Unit>): Kind<F, A>
onError Executes the given finalizer with the given error when the source is finished in error.open fun <A> Kind<F, A>.onError(finalizer: (E) -> Kind<F, Unit>): Kind<F, A>
uncancelable Meant for ensuring a given task continues execution even when interrupted.open fun <A> Kind<F, A>.uncancelable(): Kind<F, A>

Inheritors

IOBracket interface IOBracket : Bracket<ForIO, Throwable>, IOMonadThrow
MonadDefer interface MonadDefer<F> : MonadThrow<F>, Bracket<F, Throwable>

Type Class Hierarchy

Do you like Arrow?

Arrow Org
<