Safe Haskell | None |
---|---|
Language | Haskell2010 |
The SetupFunc
abstraction makes resource provider functions (of type (a -> IO r) -> IO r
) composable.
Synopsis
- newtype SetupFunc old new = SetupFunc {
- unSetupFunc :: forall r. (new -> IO r) -> old -> IO r
- makeSimpleSetupFunc :: (forall result. (resource -> IO result) -> IO result) -> SetupFunc () resource
- useSimpleSetupFunc :: SetupFunc () resource -> forall result. (resource -> IO result) -> IO result
- wrapSetupFunc :: (old -> SetupFunc () new) -> SetupFunc old new
- unwrapSetupFunc :: SetupFunc old new -> old -> SetupFunc () new
- composeSetupFunc :: SetupFunc newer newest -> SetupFunc old newer -> SetupFunc old newest
- connectSetupFunc :: SetupFunc old newer -> SetupFunc newer newest -> SetupFunc old newest
- setupAround :: SetupFunc () inner -> TestDefM outers inner result -> TestDefM outers () result
- setupAroundWith :: SetupFunc oldInner newInner -> TestDefM outers newInner result -> TestDefM outers oldInner result
- setupAroundWith' :: HContains outers outer => (outer -> SetupFunc oldInner newInner) -> TestDefM outers newInner result -> TestDefM outers oldInner result
Documentation
newtype SetupFunc old new Source #
A function that can provide an new
given an old
.
You can think of this as a potentially-resource-aware version of 'old -> IO new'.
This type has a monad instance, which means you can now compose setup functions using regular do-notation.
SetupFunc | |
|
Instances
Monad (SetupFunc old) Source # | |
Functor (SetupFunc old) Source # | |
Applicative (SetupFunc old) Source # | |
Defined in Test.Syd.Def.SetupFunc pure :: a -> SetupFunc old a # (<*>) :: SetupFunc old (a -> b) -> SetupFunc old a -> SetupFunc old b # liftA2 :: (a -> b -> c) -> SetupFunc old a -> SetupFunc old b -> SetupFunc old c # (*>) :: SetupFunc old a -> SetupFunc old b -> SetupFunc old b # (<*) :: SetupFunc old a -> SetupFunc old b -> SetupFunc old a # | |
MonadIO (SetupFunc old) Source # | |
Defined in Test.Syd.Def.SetupFunc | |
Category SetupFunc Source # | |
makeSimpleSetupFunc :: (forall result. (resource -> IO result) -> IO result) -> SetupFunc () resource Source #
Turn a simple provider function into a SetupFunc
.
This works together nicely with most supplier functions. Some examples:
useSimpleSetupFunc :: SetupFunc () resource -> forall result. (resource -> IO result) -> IO result Source #
Use a 'SetupFunc ()' as a simple provider function.
This is the opposite of the makeSimpleSetupFunc
function
wrapSetupFunc :: (old -> SetupFunc () new) -> SetupFunc old new Source #
Wrap a function that produces a SetupFunc
to into a SetupFunc
.
This is useful to combine a given 'SetupFunc b' with other 'SetupFunc ()'s as follows:
mySetupFunc :: SetupFunc B A mySetupFunc = wrapSetupFunc $ \b -> do r <- setupSomething c <- setupSomethingElse b r pure $ somehowCombine c r setupSomething :: SetupFunc () R setupSomething :: B -> R -> SetupFunc () C somehowCombine :: C -> R -> A
unwrapSetupFunc :: SetupFunc old new -> old -> SetupFunc () new Source #
Unwrap a SetupFunc
into a function that produces a SetupFunc
This is the opposite of wrapSetupFunc
.
connectSetupFunc :: SetupFunc old newer -> SetupFunc newer newest -> SetupFunc old newest Source #
Connect two setup functions.
This is basically 'flip (.)' but for SetupFunc
s.
It's exactly 'flip composeSetupFunc'.
setupAround :: SetupFunc () inner -> TestDefM outers inner result -> TestDefM outers () result Source #
setupAroundWith :: SetupFunc oldInner newInner -> TestDefM outers newInner result -> TestDefM outers oldInner result Source #
Use aroundWith
with a SetupFunc
setupAroundWith' :: HContains outers outer => (outer -> SetupFunc oldInner newInner) -> TestDefM outers newInner result -> TestDefM outers oldInner result Source #
Use aroundWith'
with a SetupFunc