FlatMap - Different Variations

val wordCount = rawDstream

.flatMap(line => line.split(" "))

.map(word => (word,1))

.reduceByKey(_+_)

.map(item => item.swap)

.transform(rdd => rdd.sortByKey(false))

.foreachRDD( rdd =>

{ rdd.take(10).foreach(x=>println("List : " + x)) }

)

val wordsFlatMap = words.flatMap(_.split("\W+"))

val evens = x.filter(i => i % 2 == 0)

can be replaced with

val evens = x.filter(_ % 2 == 0)

Scala lets you use the _ wildcard instead of a variable name when the parameter appears only once in your function,

Last updated