about summary refs log tree commit diff
path: root/lib/trivial.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-10 13:28:21 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-10 13:28:21 +0200
commit5fef92c4a0c91153e3edac3a61a232581765074a (patch)
tree291d684d0ef71e200e6d8ab5c33fc1aca467cbb3 /lib/trivial.nix
parent2a537fb369d1479748fe233261eaadfa5c2fa930 (diff)
Move pkgs/lib/ to lib/
Diffstat (limited to 'lib/trivial.nix')
-rw-r--r--lib/trivial.nix38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix
new file mode 100644
index 0000000000000..8af3474f2a671
--- /dev/null
+++ b/lib/trivial.nix
@@ -0,0 +1,38 @@
+with {
+  inherit (import ./lists.nix) deepSeqList;
+  inherit (import ./attrsets.nix) deepSeqAttrs;
+};
+
+rec {
+
+  # Identity function.
+  id = x: x;
+
+  # Constant function.
+  const = x: y: x;
+
+  # Named versions corresponding to some builtin operators.
+  concat = x: y: x ++ y;
+  or = x: y: x || y;
+  and = x: y: x && y;
+  mergeAttrs = x: y: x // y;
+  
+  # Take a function and evaluate it with its own returned value.
+  fix = f: let result = f result; in result;
+
+  # Flip the order of the arguments of a binary function.
+  flip = f: a: b: f b a;
+
+  # `seq x y' evaluates x, then returns y.  That is, it forces strict
+  # evaluation of its first argument.
+  seq = x: y: if x == null then y else y;
+  
+  # Like `seq', but recurses into lists and attribute sets to force evaluation
+  # of all list elements/attributes.
+  deepSeq = x: y:
+    if builtins.isList x
+      then deepSeqList x y
+    else if builtins.isAttrs x
+      then deepSeqAttrs x y
+      else seq x y;
+}