diff options
author | Shea Levy <shea@shealevy.com> | 2013-02-01 00:39:26 -0500 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2013-02-01 00:39:26 -0500 |
commit | da3be9c6b23ac6677821597223c142034b2b7c91 (patch) | |
tree | 4c9688b21fac4ae20c2825497b15e746d9fa547c | |
parent | 00258a362d6d9571d1e16524c5ee17fe0ef824a2 (diff) | |
download | nixlib-da3be9c6b23ac6677821597223c142034b2b7c91.tar nixlib-da3be9c6b23ac6677821597223c142034b2b7c91.tar.gz nixlib-da3be9c6b23ac6677821597223c142034b2b7c91.tar.bz2 nixlib-da3be9c6b23ac6677821597223c142034b2b7c91.tar.lz nixlib-da3be9c6b23ac6677821597223c142034b2b7c91.tar.xz nixlib-da3be9c6b23ac6677821597223c142034b2b7c91.tar.zst nixlib-da3be9c6b23ac6677821597223c142034b2b7c91.zip |
Add deepSeq lib function
-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; } |