accumulate


accumulate(fn, init, seq)
      

Return init if the sequence seq is empty. If it is not empty, apply the function fn to init and the head of seq, then recur with the value returned by fn in place of init and the tail of seq.

Return the final value of fn.

Examples:


function ints(n)
  when (n < 10) n:~ints(n+1)

let s = ints(1)
s = accumulate(`+`, 0, s)
s
// 1:<promise>
second(s)
// 3
third(s)
// 6
      

Also see:

fold_left


Core Module Index | Contents