foldList (Function)

Signature: foldList(list: List<t0>, initial: t1, function: (t1, t0) -> t1) -> t1

Description: Reduces a list to a single value by repeatedly applying a function.

Parameters

  • list (List<t0>): The list to reduce
  • initial (t1): The initial value for the accumulator
  • function ((t1, t0) -> t1): The reduction function that takes (accumulator, current) and returns the new accumulator

Returns: t1

Example

print(foldList([1, 2, 3], 0, wrapAdd))  // 6
print (foldList ([1, 2, 3], 0, wrapAdd))  // 6