mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-01-31 15:36:47 +02:00
doc: primops: add more info for foldl (#9254)
* doc: primops: add more info for foldl From the existing doc it is not obvious whether the first or the second argument is the accumulator. This is however relevant to know, as for certain scenarios, this might change the behavior. Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
This commit is contained in:
parent
bf13943206
commit
2ce8c9650b
1 changed files with 10 additions and 3 deletions
|
@ -3179,9 +3179,16 @@ static RegisterPrimOp primop_foldlStrict({
|
|||
.doc = R"(
|
||||
Reduce a list by applying a binary operator, from left to right,
|
||||
e.g. `foldl' op nul [x0 x1 x2 ...] = op (op (op nul x0) x1) x2)
|
||||
...`. For example, `foldl' (x: y: x + y) 0 [1 2 3]` evaluates to 6.
|
||||
The return value of each application of `op` is evaluated immediately,
|
||||
even for intermediate values.
|
||||
...`.
|
||||
|
||||
For example, `foldl' (acc: elem: acc + elem) 0 [1 2 3]` evaluates
|
||||
to `6` and `foldl' (acc: elem: { "${elem}" = elem; } // acc) {}
|
||||
["a" "b"]` evaluates to `{ a = "a"; b = "b"; }`.
|
||||
|
||||
The first argument of `op` is the accumulator wheres the second
|
||||
argument is the current element being processed. The return value
|
||||
of each application of `op` is evaluated immediately, even for
|
||||
intermediate values.
|
||||
)",
|
||||
.fun = prim_foldlStrict,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue