Skip to content

Commit

Permalink
Add handleWith
Browse files Browse the repository at this point in the history
  • Loading branch information
arybczak committed Aug 8, 2024
1 parent aff86ac commit 203f022
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions effectful-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# effectful-core-2.4.0.0 (????-??-??)
* Add `handleWith` (`interpret` with flipped arguments) to
`Effectful.Dispatch.Dynamic`.
* Add utility functions for handling first order effects to
`Effectful.Dispatch.Dynamic`.

Expand Down
24 changes: 24 additions & 0 deletions effectful-core/src/Effectful/Dispatch/Dynamic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Effectful.Dispatch.Dynamic
, reinterpret
, interpose
, impose
, handleWith

-- ** Handling local 'Eff' computations
, LocalEnv
Expand Down Expand Up @@ -59,6 +60,7 @@ module Effectful.Dispatch.Dynamic
, reinterpret_
, interpose_
, impose_
, handleWith_

-- * Re-exports
, HasCallStack
Expand Down Expand Up @@ -533,6 +535,17 @@ impose runHandlerEs handler m = unsafeEff $ \es -> do
where
mkHandler es = Handler es (let ?callStack = thawCallStack ?callStack in handler)

-- | 'interpret' with flipped arguments.
--
-- @since 2.4.0.0
handleWith
:: DispatchOf e ~ Dynamic
=> Eff (e : es) a
-> EffectHandler e es
-- ^ The effect handler.
-> Eff es a
handleWith m handler = interpret handler m

----------------------------------------
-- First order effects

Expand Down Expand Up @@ -593,6 +606,17 @@ impose_
-> Eff es b
impose_ runHandlerEs handler = impose runHandlerEs (const handler)

-- | 'handleWith' for first order effects.
--
-- @since 2.4.0.0
handleWith_
:: DispatchOf e ~ Dynamic
=> Eff (e : es) a
-> EffectHandler_ e es
-- ^ The effect handler.
-> Eff es a
handleWith_ m handler = interpret_ handler m

----------------------------------------
-- Unlifts

Expand Down
2 changes: 2 additions & 0 deletions effectful/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# effectful-2.4.0.0 (????-??-??)
* Add `handleWith` (`interpret` with flipped arguments) to
`Effectful.Dispatch.Dynamic`.
* Add utility functions for handling first order effects to
`Effectful.Dispatch.Dynamic`.

Expand Down

0 comments on commit 203f022

Please sign in to comment.