query
On this page

assertOneOf

lib.asserts.assertOneOf

Docs pulled from | This Revision | 10 minutes ago


Specialized assertMsg for checking if val is one of the elements of the list xs. Useful for checking enums.

Inputs

name

The name of the variable the user entered val into, for inclusion in the error message

val

The value of what the user provided, to be compared against the values in xs

xs

The list of valid values

Type

assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool

Examples

lib.asserts.assertOneOf usage example

let sslLibrary = "libressl";
in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ]
stderr> error: sslLibrary must be one of [
stderr>   "openssl"
stderr>   "bearssl"
stderr> ], but is: "libressl"

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

assertOneOf =
    name: val: xs:
    assertMsg (lib.elem val xs) "${name} must be one of ${lib.generators.toPretty { } xs}, but is: ${
      lib.generators.toPretty { } val
    }";