lib.lists.foldl': Make strict in the initial accumulator

To maintain backwards compatibility, this can't be changed in the Nix language.
We can however ensure that the version Nixpkgs has the more intuitive behavior.
This commit is contained in:
Silvan Mosberger
2023-09-22 12:22:04 +02:00
parent 857a844ea8
commit 3b6169f87b
4 changed files with 16 additions and 6 deletions

View File

@@ -524,10 +524,10 @@ runTests {
expected = [ 3 2 1 ];
};
# The same as builtins.foldl', lib.foldl' doesn't evaluate the first accumulator strictly
# Compared to builtins.foldl', lib.foldl' evaluates the first accumulator strictly too
testFoldl'StrictInitial = {
expr = (builtins.tryEval (foldl' (acc: el: el) (throw "hello") [])).success;
expected = true;
expected = false;
};
# Make sure we don't get a stack overflow for large lists