| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Skeletest.Internal.Hooks.HookDef
Contents
Synopsis
- newtype Hook ctx inp out = Hook [HookDef ctx inp out]
- data HookDef ctx inp out = HookDef {
- priority :: HookPriority
- impl :: ctx -> (inp -> IO out) -> inp -> IO out
- data HookPriority
- runHook :: Hook ctx inp out -> ctx -> inp -> (inp -> IO out) -> IO out
- runEarly :: Hook ctx inp out -> Hook ctx inp out
- runLate :: Hook ctx inp out -> Hook ctx inp out
- mkHook :: (ctx -> (inp -> IO out) -> inp -> IO out) -> Hook ctx inp out
- mkHook_ :: (ctx -> inp -> IO ()) -> (ctx -> inp -> out -> IO ()) -> Hook ctx inp out
- mkPreHook :: (ctx -> inp -> IO inp) -> Hook ctx inp out
- mkPreHook_ :: (ctx -> inp -> IO ()) -> Hook ctx inp out
- mkPostHook :: (ctx -> inp -> out -> IO out) -> Hook ctx inp out
- mkPostHook_ :: (ctx -> inp -> out -> IO ()) -> Hook ctx inp out
Documentation
newtype Hook ctx inp out Source #
The implementation of a Skeletest hook in Hooks.
A hook of type Hook ctx inp out means:
- The hook takes a value of type
ctxwith extra read-only information that may be relevant for the hook. - The hook takes an action of type
inp -> IO outand returns a potentially modified action of the same type.
ctx/inp should generally be accessed with OverloadedRecordDot or record
destructuring, to minimize breaking changes when adding fields to them.
data HookPriority Source #
Constructors
| NoPriority | |
| EarlyPriority | |
| LatePriority |
Hook DSL
mkHook :: (ctx -> (inp -> IO out) -> inp -> IO out) -> Hook ctx inp out Source #
Create a hook.
Example
hooks :: Hooks
hooks =
defaultHooks
{ runSpecs = runEarly . mkHook $ ctx run -> pre >=> run >=> post
}
where
pre inp = do
inp' <- doStuff inp
pure inp'
post out = do
out' <- doMoreStuff out
pure out'
mkHook_ :: (ctx -> inp -> IO ()) -> (ctx -> inp -> out -> IO ()) -> Hook ctx inp out Source #
Like mkHook, except for read-only hooks that don't need to modify
anything.
mkPreHook :: (ctx -> inp -> IO inp) -> Hook ctx inp out Source #
Like mkHook, except only supports modifying the input.
mkPreHook_ :: (ctx -> inp -> IO ()) -> Hook ctx inp out Source #
Like mkHook_, except with only a before action.