From da3be9c6b23ac6677821597223c142034b2b7c91 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 1 Feb 2013 00:39:26 -0500 Subject: [PATCH] Add deepSeq lib function --- pkgs/lib/attrsets.nix | 3 ++- pkgs/lib/lists.nix | 4 ++++ pkgs/lib/trivial.nix | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 5e0ab620865..fcdc3c31f29 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 ede7018fb23..0916355568c 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 af47a8c8841..e971dd6d80e 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; }