summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorannalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com>2024-04-05 00:09:07 +0000
committerannalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com>2024-04-05 00:09:07 +0000
commit6df4f7b89bebf25f2210e1b31eb983b3aa1d00df (patch)
treed165685e916ff684cd1760fa245fcd9cf936c669 /lib
parent36cd37b5dcfa3e86133f9663c2deb0278bcdcd18 (diff)
parent0048ef6deb17ada59f4445b8ba6f7d474e8fb1cd (diff)
Merge remote-tracking branch 'upstream/staging-next' into staging
Conflicts: pkgs/development/python-modules/pynetdicom/default.nix
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix2
-rw-r--r--lib/tests/misc.nix16
-rw-r--r--lib/trivial.nix18
3 files changed, 35 insertions, 1 deletions
diff --git a/lib/default.nix b/lib/default.nix
index f6cb7932507a..b442ddf5fa0f 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -69,7 +69,7 @@ let
hasAttr head isAttrs isBool isInt isList isPath isString length
lessThan listToAttrs pathExists readFile replaceStrings seq
stringLength sub substring tail trace;
- inherit (self.trivial) id const pipe concat or and bitAnd bitOr bitXor
+ inherit (self.trivial) id const pipe concat or and xor bitAnd bitOr bitXor
bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max
importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum
info showWarnings nixpkgsVersion version isInOldestRelease
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index da5e32297509..accceb4ddf9c 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -106,6 +106,7 @@ let
types
updateManyAttrsByPath
versions
+ xor
;
testingThrow = expr: {
@@ -214,6 +215,21 @@ runTests {
expected = false;
};
+ testXor = {
+ expr = [
+ (xor true false)
+ (xor true true)
+ (xor false false)
+ (xor false true)
+ ];
+ expected = [
+ true
+ false
+ false
+ true
+ ];
+ };
+
testFix = {
expr = fix (x: {a = if x ? a then "a" else "b";});
expected = {a = "a";};
diff --git a/lib/trivial.nix b/lib/trivial.nix
index 936ad207c03d..5b7a1ee30f7a 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);