-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib.asserts.assertAll: init #215166
base: master
Are you sure you want to change the base?
lib.asserts.assertAll: init #215166
Conversation
construct an error message. | ||
|
||
Type: | ||
assertAll :: (a -> Bool) -> [a] -> (Int -> a -> String) -> Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design decisions:
-
Should it be called with named arguments instead? E.g.
# assertAll :: { # condition :: a -> Bool; # list :: [a]; # message :: Int -> a -> String; # } -> Bool assert assertAll { condition = n: n != 2; list = [ 1 3 5 ]; message = i: n: "Index ${toString i}, value ${toString n} failed."; };
RFC 135 also goes in that direction
-
Should the message have access to not only the first, but all elements that don't satisfy the condition? The module system has such a use case:
Lines 765 to 767 in 12053de
if all (def: type.check def.value) defsFinal then type.merge loc defsFinal else let allInvalid = filter (def: ! type.check def.value) defsFinal; in throw "A definition for option `${showOption loc}' is not of type `${type.description}'. Definition values:${showDefs allInvalid}"
How should this look like? Maybe# assertAll :: { # condition :: a -> Bool; # list :: [a]; # message :: [{ index :: Int; value :: a; }] -> String; # } -> Bool assert assertAll { condition = n: n != 2; list = [ 1 2 3 ]; message = failingElements: "Index ${(head failingElements).index}, value ${(head failingElements).value} failed.";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Yes, and to make it like RFC 135, it should be
assertAll = {success, message}: list: ...
- Sounds good. Possibly with an index attached? Needs more thinking and discussion.
Description of changes
Split off from #209099 where this function is useful. It can also be used for #209375
This work is sponsored by Antithesis ✨
Things done