mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
lib/trivial: add warnIfNot and throwIf
Negated versions of warnIf and throwIfNot.
This commit is contained in:
parent
83e8ce412b
commit
7fae930a37
1 changed files with 15 additions and 1 deletions
|
@ -323,7 +323,14 @@ rec {
|
||||||
|
|
||||||
Type: bool -> string -> a -> a
|
Type: bool -> string -> a -> a
|
||||||
*/
|
*/
|
||||||
warnIf = cond: msg: if cond then warn msg else id;
|
warnIf = cond: msg: if cond then warn msg else x: x;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Like warnIf, but negated (warn if the first argument is `false`).
|
||||||
|
|
||||||
|
Type: bool -> string -> a -> a
|
||||||
|
*/
|
||||||
|
warnIfNot = cond: msg: if cond then x: x else warn msg;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Like the `assert b; e` expression, but with a custom error message and
|
Like the `assert b; e` expression, but with a custom error message and
|
||||||
|
@ -347,6 +354,13 @@ rec {
|
||||||
*/
|
*/
|
||||||
throwIfNot = cond: msg: if cond then x: x else throw msg;
|
throwIfNot = cond: msg: if cond then x: x else throw msg;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Like throwIfNot, but negated (throw if the first argument is `true`).
|
||||||
|
|
||||||
|
Type: bool -> string -> a -> a
|
||||||
|
*/
|
||||||
|
throwIf = cond: msg: if cond then throw msg else x: x;
|
||||||
|
|
||||||
/* Check if the elements in a list are valid values from a enum, returning the identity function, or throwing an error message otherwise.
|
/* Check if the elements in a list are valid values from a enum, returning the identity function, or throwing an error message otherwise.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue