Closed ChristianGruen closed 10 months ago
If the computed result in a fold function does not change anymore, the remaining computations can be skipped. Examples:
fold-left($huge, 1, fn($result, $item) { true() }) fold-left($huge, 1, fn($result, $item) { $result }) fold-left($huge, 1, fn($result, $item) { if($result > 100) then $result else $result + $item }) fold-left($huge, 1, fn($result, $item) { if($result < 100) then $result + $item else $result })
The same applies to fold-right, array:fold-left and array:fold-right.
fold-right
array:fold-left
array:fold-right
If the computed result in a fold function does not change anymore, the remaining computations can be skipped. Examples:
The same applies to
fold-right
,array:fold-left
andarray:fold-right
.