Scala map and filter methods
map(func) and filter(func) Both are first class methods. First class methods take function as input parameter or output as function.
Functional programming: Programming focusing on a function is used as input parameter of another function or methods or as output of another function or method

map(func) method:

1
sc.parallelize(Seq(1,2,3,4,5)).map(x=>x+1).collect
2
/*
3
res0: Array[Int] = Array(2, 3, 4, 5, 6)
4
*/
Copied!

filter(func)

1
sc.parallelize(Seq(1,2,3,4,5)).filter(x=>x%2==0)
2
.collect
3
/*
4
res2: Array[Int] = Array(2, 4)
5
*/
Copied!
​
Last modified 1yr ago