diff options
Diffstat (limited to 'lib/lists.nix')
-rw-r--r-- | lib/lists.nix | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/lists.nix b/lib/lists.nix index b12b78754a38..c162f921280d 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -228,7 +228,15 @@ rec { `acc` - : The initial accumulator value + : The initial accumulator value. + + The accumulator value is evaluated in any case before the first iteration starts. + + To avoid evaluation even before the `list` argument is given an eta expansion can be used: + + ```nix + list: lib.foldl' op acc list + ``` `list` @@ -254,13 +262,11 @@ rec { foldl' = op: acc: - list: - # The builtin `foldl'` is a bit lazier than one might expect. # See https://github.com/NixOS/nix/pull/7158. # In particular, the initial accumulator value is not forced before the first iteration starts. builtins.seq acc - (builtins.foldl' op acc list); + (builtins.foldl' op acc); /** Map with index starting from 0 |