checkListOfEnum
lib.checkListOfEnum
Docs pulled from | This Revision | 10 minutes ago
Check if the elements in a list are valid values from a enum, returning the identity function, or throwing an error message otherwise.
Inputs
msg
-
1. Function argument
valid
-
2. Function argument
given
-
3. Function argument
Type
String -> List ComparableVal -> List ComparableVal -> a -> a
Examples
lib.trivial.checkListOfEnum
usage example
let colorVariants = ["bright" "dark" "black"]
in checkListOfEnum "color variants" [ "standard" "light" "dark" ] colorVariants;
=>
error: color variants: bright, black unexpected; valid ones: standard, light, dark
Noogle detected
Implementation
The following is the current implementation of this function.
checkListOfEnum = msg: valid: given:
let
unexpected = lib.subtractLists valid given;
in
lib.throwIfNot (unexpected == [])
"${msg}: ${builtins.concatStringsSep ", " (builtins.map builtins.toString unexpected)} unexpected; valid ones: ${builtins.concatStringsSep ", " (builtins.map builtins.toString valid)}";