assertEachOneOf
lib.asserts.assertEachOneOf
Docs pulled from | This Revision | 18 days ago
Nixpkgs manual
Specialized assertMsg for checking if every one of vals is one of the elements
of the list xs. Useful for checking lists of supported attributes.
Inputs
name-
The name of the variable the user entered
valinto, for inclusion in the error message vals-
The list of values of what the user provided, to be compared against the values in
xs xs-
The list of valid values
Type
assertEachOneOf :: String -> [ComparableVal] -> [ComparableVal] -> Bool
Examples
lib.asserts.assertEachOneOf usage example
let sslLibraries = [ "libressl" "bearssl" ];
in assertEachOneOf "sslLibraries" sslLibraries [ "openssl" "bearssl" ]
stderr> error: each element in sslLibraries must be one of [
stderr> "openssl"
stderr> "bearssl"
stderr> ], but is: [
stderr> "libressl"
stderr> "bearssl"
stderr> ]
Noogle detected
Implementation
The following is the current implementation of this function.
assertEachOneOf =
name: vals: xs:
assertMsg (lib.all (val: lib.elem val xs) vals)
"each element in ${name} must be one of ${lib.generators.toPretty { } xs}, but is: ${
lib.generators.toPretty { } vals
}";