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): 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

foldList([1, 2, 3], 0, fn(acc, n) => acc + n)  // 6
foldList ([1, 2, 3], 0, \(acc, n) => acc + n)  // 6