2013-01-31 22:39:26 -07:00
|
|
|
with {
|
|
|
|
inherit (import ./lists.nix) deepSeqList;
|
|
|
|
inherit (import ./attrsets.nix) deepSeqAttrs;
|
|
|
|
};
|
|
|
|
|
2009-02-09 09:51:03 -07:00
|
|
|
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;
|
2009-07-02 02:58:30 -06:00
|
|
|
mergeAttrs = x: y: x // y;
|
2009-02-09 09:51:03 -07:00
|
|
|
|
|
|
|
# Take a function and evaluate it with its own returned value.
|
|
|
|
fix = f: let result = f result; in result;
|
|
|
|
|
2009-10-23 01:34:56 -06:00
|
|
|
# Flip the order of the arguments of a binary function.
|
|
|
|
flip = f: a: b: f b a;
|
|
|
|
|
2010-08-19 06:37:10 -06:00
|
|
|
# `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;
|
|
|
|
|
2013-02-04 05:20:14 -07:00
|
|
|
# Like `seq', but recurses into lists and attribute sets to force evaluation
|
|
|
|
# of all list elements/attributes.
|
2013-01-31 22:39:26 -07:00
|
|
|
deepSeq = x: y:
|
|
|
|
if builtins.isList x
|
|
|
|
then deepSeqList x y
|
|
|
|
else if builtins.isAttrs x
|
|
|
|
then deepSeqAttrs x y
|
|
|
|
else seq x y;
|
2009-02-09 09:51:03 -07:00
|
|
|
}
|