diff options
author | edef <edef@edef.eu> | 2024-04-04 14:05:18 +0000 |
---|---|---|
committer | edef <edef@edef.eu> | 2024-04-04 19:46:58 +0000 |
commit | 725bb4e48c6491598f53b83c2dcd1a307115c6cc (patch) | |
tree | 5e801c1cd8677cefd283e63ec3d0fc5484df98d4 /lib/trivial.nix | |
parent | d03a4482228d4d6dbd2d4b425b6dfcd49ebe765f (diff) |
lib: add xor
This gets clumsily reimplemented in various places, to no useful end.
Diffstat (limited to 'lib/trivial.nix')
-rw-r--r-- | lib/trivial.nix | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix index 936ad207c03df..5b7a1ee30f7ad 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -200,6 +200,24 @@ in { and = x: y: x && y; /** + boolean “exclusive or” + + + # Inputs + + `x` + + : 1\. Function argument + + `y` + + : 2\. Function argument + */ + # We explicitly invert the arguments purely as a type assertion. + # This is invariant under XOR, so it does not affect the result. + xor = x: y: (!x) != (!y); + + /** bitwise “not” */ bitNot = builtins.sub (-1); |