Array.foldl()

From ZCubes Wiki
Revision as of 15:25, 15 February 2020 by Joseph (talk | contribs)
Jump to navigation Jump to search


Array.foldl(SomFunction, SomeStartValue)

At each element, SomeFunction (that can take two parameter values) are called in sequence for element from the left. The second parameter is the last value of evaluation of the given SomeFunction. For the very first element, the SomeStartValue is passed as the second parameter, if present. If no SomeStartValue is provided, it starts with the first two as the pair to start with.


a=1..5; a.foldl( function (last,x) { OUTPUT([last,x,(last-x)]); return(last-x) }, 0 )

1 2 -1

-1 3 -4

-4 4 -8

-8 5 -13

-13


a=1..5; a.foldl( function (last,x) { OUTPUT([last,x,(last-x)]); return(last-x) } )

1 2 -1

-1 3 -4

-4 4 -8

-8 5 -13

-13

See Also

foldl

foldr