Open
Description
It seems like a good library.
The use - may need an explanation to users.
The result may form a tutorial.
My case to understand how library works.
Suppose I use the code (using a bit harder than trivial case so to have a relevant example/help), where the base function is:
(ExpectedHask, NixLang) -> Assertion
:
type NixLang = Text
type ExpectedHask = Integer -- lets provide a stub to make Hask happy. (in code, it is a deeply embedded DSL (Nix) data type)
assertParseText :: ExpectedHask -> NixLang -> Assertion
assertParseText = undefined
-- | This class constructs functions that accept a variadic number of arguments.
-- Every argument is an assertion.
-- So now the new assertions can be added just by adding it to a block of according assertions.
class VariadicAssertions t where
checkListPairs' :: ((ExpectedHask, NixLang) -> Assertion) -> [(ExpectedHask, NixLang)] -> t
instance VariadicAssertions (IO a) where
checkListPairs' f acc =
do
traverse_ f acc
pure $ error "never would be reached, cuz `I'm lazy`."
instance (VariadicAssertions a) => VariadicAssertions ((ExpectedHask, NixLang) -> a) where
checkListPairs' f acc x = checkListPairs' f (acc <> [x])
-- | The main function under question, variadicly assepts @(ExpectedHask, NixLang)@ pairs & runs assertion check on each pair.
checks :: (VariadicAssertions a) => a
checks = checkListPairs' (uncurry assertParseText) []
-- Used as:
case_constant_bool :: Assertion
case_constant_bool =
checks
( 1 -- in code @mkBool True@
, "true" -- NixLang
)
( 0 -- in code @mkBool False@
, "false" -- NixLang
)
The exempt from the current haskell-nix/hnix#970.
Question:
Please, help with an example of how to leverage the library. In this case, to change the checks
function so it uses library & achieves the same (ideal) or nearly the same result.
P.S.
I tried to understand & use the to/fromVariadic{,T}
and such, but so far not found how to do it & in variadic hides the type info making it hard to infer the use.
Metadata
Metadata
Assignees
Labels
No labels