fold_left


fold_left(fn, init, @rest xs, ...)
      

Return init if the list arguments xs, ... are empty. If they are not empty, apply the function fn to the heads of xs, ... and init, then recur with the value returned by fn in place of init and the tails of xs, ....

The list arguments should all have the same length. Fn should accept one more argument than the number of list arguments and return a single value. It should not mutate the lists.

Examples:


fold_left(^(x, init) init + x * x, 0, [1, 2, 3, 4, 5])
// 55

fold_left(pair, [], [1,2,3,4])
// [4, 3, 2, 1]

fold_left(`-`, 0, [1, 2, 3, 4])
// 2
      

Also see:

fold
fold_right
accumulate
map


Core Module Index | Contents