Add deepSeq lib function
This commit is contained in:
parent
00258a362d
commit
da3be9c6b2
|
@ -5,7 +5,7 @@ with {
|
||||||
inherit (import ./trivial.nix) or;
|
inherit (import ./trivial.nix) or;
|
||||||
inherit (import ./default.nix) fold;
|
inherit (import ./default.nix) fold;
|
||||||
inherit (import ./strings.nix) concatStringsSep;
|
inherit (import ./strings.nix) concatStringsSep;
|
||||||
inherit (import ./lists.nix) concatMap concatLists all;
|
inherit (import ./lists.nix) concatMap concatLists all deepSeqList;
|
||||||
inherit (import ./misc.nix) maybeAttr;
|
inherit (import ./misc.nix) maybeAttr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -314,4 +314,5 @@ rec {
|
||||||
overrideExisting = old: new:
|
overrideExisting = old: new:
|
||||||
old // listToAttrs (map (attr: nameValuePair attr (attrByPath [attr] (getAttr attr old) new)) (attrNames old));
|
old // listToAttrs (map (attr: nameValuePair attr (attrByPath [attr] (getAttr attr old) new)) (attrNames old));
|
||||||
|
|
||||||
|
deepSeqAttrs = x: y: deepSeqList (attrValues x) y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
# General list operations.
|
# General list operations.
|
||||||
|
with {
|
||||||
|
inherit (import ./trivial.nix) deepSeq;
|
||||||
|
};
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
inherit (builtins) head tail length isList add sub lessThan;
|
inherit (builtins) head tail length isList add sub lessThan;
|
||||||
|
@ -220,4 +223,5 @@ rec {
|
||||||
++ zipTwoLists (tail xs) (tail ys)
|
++ zipTwoLists (tail xs) (tail ys)
|
||||||
else [];
|
else [];
|
||||||
|
|
||||||
|
deepSeqList = xs: y: if any (x: deepSeq x false) xs then y else y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
with {
|
||||||
|
inherit (import ./lists.nix) deepSeqList;
|
||||||
|
inherit (import ./attrsets.nix) deepSeqAttrs;
|
||||||
|
};
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
|
|
||||||
# Identity function.
|
# Identity function.
|
||||||
|
@ -22,4 +27,10 @@ rec {
|
||||||
# evaluation of its first argument.
|
# evaluation of its first argument.
|
||||||
seq = x: y: if x == null then y else y;
|
seq = x: y: if x == null then y else y;
|
||||||
|
|
||||||
|
deepSeq = x: y:
|
||||||
|
if builtins.isList x
|
||||||
|
then deepSeqList x y
|
||||||
|
else if builtins.isAttrs x
|
||||||
|
then deepSeqAttrs x y
|
||||||
|
else seq x y;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue