Reduce is a function or method that is used to take the values in an array or a list and apply a function to successive members of the list to produce (or reduce them to), a single value.



Task

Show how reduce (or foldl or foldr etc), work (or would be implemented) in your language.



See also

 Wikipedia article:   Fold
 Wikipedia article:   Catamorphism


procedure main(A)
    write(A[1],": ",curry(A[1],A[2:0]))
end
 
procedure curry(f,A)
    r := A[1]
    every r := f(r, !A[2:0])
    return r
end