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


> nums := seq( 1 .. 10 );
                          nums := 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
 
> foldl( `+`, 0, nums ); # compute sum using foldl
                          55
 
> foldr( `*`, 1, nums ); # compute product using foldr
                          3628800