Assert functions

lib.asserts.assertMsg

assertMsg :: Bool -> String -> Bool

Throw if pred is false, else return pred. Intended to be used to augment asserts with helpful error messages.

pred

Condition under which the msg should not be printed

msg

Message to print

lib.asserts.assertMsg usage example

assertMsg false "nope"
stderr> error: nope

assert assertMsg ("foo" == "bar") "foo is not bar, silly"; ""
stderr> error: foo is not bar, silly

lib.asserts.assertOneOf

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

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

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

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"