handle package:bluefin-internal

handle, but with the argument order swapped
>>> runPureEff $ handle (pure . show) $ \e -> do
throw e 42
pure "No exception thrown"
"42"
You can define a Handle instance for your compound handles. As an example, an "application" handle with a dynamic effect for database queries, a concrete effect for application state and a concrete effect for a logging effect might look like this:
data Application e = MkApplication
{ queryDatabase :: forall e'. String -> Int -> Eff (e' :& e) [String],
applicationState :: State (Int, Bool) e,
logger :: Stream String e
}
To define mapHandle for Application you should apply mapHandle to all the fields that are themeselves handles and apply useImplUnder to all the fields that are dynamic effects:
instance Handle Application where
mapHandle
MkApplication
{ queryDatabase = q,
applicationState = a,
logger = l
} =
MkApplication
{ queryDatabase = s i -> useImplUnder (q s i),
applicationState = mapHandle a,
logger = mapHandle l
}
Used to create compound effects, i.e. handles that contain other handles.