Add bracket

with minor edits by @tomjaguarpaw
This commit is contained in:
Li-yao Xia 2024-04-27 12:25:00 +02:00 committed by Tom Ellis
parent 65a9af3949
commit 34b28d19e8
2 changed files with 15 additions and 0 deletions

View File

@ -390,6 +390,19 @@ catch ::
Eff es a
catch f h = handle h f
-- | @bracket acquire release body@: @acquire@ a resource, perform the
-- @body@ with it, and @release@ the resource even if @body@ threw an
-- exception. This is essentially the same as
-- @Control.Exception.'Control.Exception.bracket'@, whose
-- documentation you can inspect for further details.
bracket ::
Eff es a ->
(a -> Eff es ()) ->
(a -> Eff es b) ->
Eff es b
bracket before after body = UnsafeMkEff $ Control.Exception.bracket
(unsafeUnEff before) (unsafeUnEff . after) (unsafeUnEff . body)
-- |
-- @
-- >>> runPureEff $ runState 10 $ \\st -> do

View File

@ -4,6 +4,8 @@ module Bluefin.Eff
-- * Run an 'Eff'
runPureEff,
runEff,
-- * Resource management
bracket,
-- * Type classes
-- | See "Bluefin.Eff.IO" for the most direct way of doing I/O in