mirror of
https://github.com/NixOS/nix
synced 2025-07-07 18:31:49 +02:00
Merge pull request #7158 from sternenseemann/foldl-strict-accumulation-value
This commit is contained in:
commit
dda83a59c1
6 changed files with 25 additions and 3 deletions
|
@ -0,0 +1,5 @@
|
|||
# Tests that the result of applying op is forced even if the value is never used
|
||||
builtins.foldl'
|
||||
(_: f: f null)
|
||||
null
|
||||
[ (_: throw "Not the final value, but is still forced!") (_: 23) ]
|
1
tests/lang/eval-okay-foldlStrict-lazy-elements.exp
Normal file
1
tests/lang/eval-okay-foldlStrict-lazy-elements.exp
Normal file
|
@ -0,0 +1 @@
|
|||
42
|
9
tests/lang/eval-okay-foldlStrict-lazy-elements.nix
Normal file
9
tests/lang/eval-okay-foldlStrict-lazy-elements.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Tests that the rhs argument of op is not forced unconditionally
|
||||
let
|
||||
lst = builtins.foldl'
|
||||
(acc: x: acc ++ [ x ])
|
||||
[ ]
|
||||
[ 42 (throw "this shouldn't be evaluated") ];
|
||||
in
|
||||
|
||||
builtins.head lst
|
|
@ -0,0 +1 @@
|
|||
42
|
|
@ -0,0 +1,6 @@
|
|||
# Checks that the nul value for the accumulator is not forced unconditionally.
|
||||
# Some languages provide a foldl' that is strict in this argument, but Nix does not.
|
||||
builtins.foldl'
|
||||
(_: x: x)
|
||||
(throw "This is never forced")
|
||||
[ "but the results of applying op are" 42 ]
|
Loading…
Add table
Add a link
Reference in a new issue