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


 
-module(catamorphism).
 
-export([test/0]).
 
test() ->
	Nums = lists:seq(1,10),
	Summation = 
		lists:foldl(fun(X, Acc) -> X + Acc end, 0, Nums),
	Product = 
		lists:foldl(fun(X, Acc) -> X * Acc end, 1, Nums),
	Concatenation = 
		lists:foldr(
			fun(X, Acc) -> integer_to_list(X) ++ Acc end, 
			"", 
			Nums),
	{Summation, Product, Concatenation}.
 