Slide 3
Slide 3 text
Map and Reduce traditional collection operations
1. Ruby
(1..5).map{|x| x*2 } #=> [2, 4, 6, 8, 10]
(1..5).reduce(:+) #=> 15
2.Python
map(lambda x: x**2, range(5))
reduce(lambda x, y: x + y, range(5))
3.Scala
(1 to 5).map(number => number * 2)
(1 to 5).reduce((a, b) => a + b)
4.Clojure
(map inc [1 2 3 4 5])
(reduce + [1 2 3 4 5])
4.Java
List tempList = new ArrayList();
for(T elem : elements){
tempList.add(elem * 2)
}
int result = 0;
for(T elem : elements){
result += elem
}
3