> For the complete documentation index, see [llms.txt](https://nag-9-s.gitbook.io/spark-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nag-9-s.gitbook.io/spark-notes/flatmap-different-variations.md).

# 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,
