diff options
-rw-r--r-- | pkgs/lib/attrsets.nix | 3 | ||||
-rw-r--r-- | pkgs/lib/lists.nix | 4 | ||||
-rw-r--r-- | pkgs/lib/trivial.nix | 11 |
3 files changed, 17 insertions, 1 deletions
diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 5e0ab6208651..fcdc3c31f290 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -5,7 +5,7 @@ with { inherit (import ./trivial.nix) or; inherit (import ./default.nix) fold; 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; }; @@ -314,4 +314,5 @@ rec { overrideExisting = old: new: old // listToAttrs (map (attr: nameValuePair attr (attrByPath [attr] (getAttr attr old) new)) (attrNames old)); + deepSeqAttrs = x: y: deepSeqList (attrValues x) y; } diff --git a/pkgs/lib/lists.nix b/pkgs/lib/lists.nix index ede7018fb236..0916355568c3 100644 --- a/pkgs/lib/lists.nix +++ b/pkgs/lib/lists.nix @@ -1,4 +1,7 @@ # General list operations. +with { + inherit (import ./trivial.nix) deepSeq; +}; rec { inherit (builtins) head tail length isList add sub lessThan; @@ -220,4 +223,5 @@ rec { ++ zipTwoLists (tail xs) (tail ys) else []; + deepSeqList = xs: y: if any (x: deepSeq x false) xs then y else y; } diff --git a/pkgs/lib/trivial.nix b/pkgs/lib/trivial.nix index af47a8c88415..e971dd6d80e7 100644 --- a/pkgs/lib/trivial.nix +++ b/pkgs/lib/trivial.nix @@ -1,3 +1,8 @@ +with { + inherit (import ./lists.nix) deepSeqList; + inherit (import ./attrsets.nix) deepSeqAttrs; +}; + rec { # Identity function. @@ -22,4 +27,10 @@ rec { # evaluation of its first argument. 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; } |