summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-03-19 20:39:52 +0100
committerNaïm Favier <n@monade.li>2022-03-19 20:40:40 +0100
commit7fae930a37a06fe08d4f85d6f41b04b37ed05cd0 (patch)
tree45e1d84459bbe953d560af11e5eecb690c916f55 /lib
parent83e8ce412b4c7561b28acc924bd46a4bd08c2351 (diff)
downloadnixpkgs-7fae930a37a06fe08d4f85d6f41b04b37ed05cd0.tar
nixpkgs-7fae930a37a06fe08d4f85d6f41b04b37ed05cd0.tar.gz
nixpkgs-7fae930a37a06fe08d4f85d6f41b04b37ed05cd0.tar.bz2
nixpkgs-7fae930a37a06fe08d4f85d6f41b04b37ed05cd0.tar.lz
nixpkgs-7fae930a37a06fe08d4f85d6f41b04b37ed05cd0.tar.xz
nixpkgs-7fae930a37a06fe08d4f85d6f41b04b37ed05cd0.tar.zst
nixpkgs-7fae930a37a06fe08d4f85d6f41b04b37ed05cd0.zip
lib/trivial: add warnIfNot and throwIf
Negated versions of warnIf and throwIfNot.
Diffstat (limited to 'lib')
-rw-r--r--lib/trivial.nix16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix
index c68bac902e9..fd0c9aba4ff 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -323,7 +323,14 @@ rec {
 
     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
@@ -347,6 +354,13 @@ rec {
   */
   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.
 
      Example: