Skip to content

Commit

Permalink
Computation
Browse files Browse the repository at this point in the history
  • Loading branch information
raganwald authored Apr 12, 2024
1 parent 76f69fa commit 60725aa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion _posts/2017-04-10-foldl-foldr.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ valueToCompute = foldr(fn, valueToCompute, iterator);
return fn(current, valueToCompute);
```

The remainder of the compputation is evaluated first using recursion, and then its passed to the folding function `fn`. This is what makes it right-associative: Givien `0 - 1 - 2 - 3 - 4 - 5`, it computes `1 - (2 - (3 - (4 - 5))) => 3` first, then returns `0 - 3` as the final result.
The remainder of the computation is evaluated first using recursion, and then its passed to the folding function `fn`. This is what makes it right-associative: Givien `0 - 1 - 2 - 3 - 4 - 5`, it computes `1 - (2 - (3 - (4 - 5))) => 3` first, then returns `0 - 3` as the final result.

Although it consumes its elements from the left, `foldr` associates its operations from the right.

Expand Down

0 comments on commit 60725aa

Please sign in to comment.