pen'] ↓ map (\x -> x.split(" ")) [['this', 'is', 'a', 'pen'], ['this', 'is', 'an', 'apple'], ['apple', 'pen']] ↓ flatten ['this', 'is', 'a', 'pen', 'this', 'is', 'an', 'apple', 'apple', 'pen'] ↓ map (\x -> (x, 1)) [('this', 1), ('is', 1), ('a', 1), ('pen', 1), ('this', 1), ('is', 1), ('an', 1), ('apple', 1), ('apple', 1), ('pen', 1)] ↓ groupByKey [('a', [1]), ('apple', [1, 1]), ('this', [1, 1]), ('is', [1, 1]), ('an', [1]), ('pen', [1, 1])] ↓ map (\(k, v) -> (k, sum(v)) [('a', 1), ('apple', 2), ('this', 2), ('is', 2), ('an', 1), ('pen', 2)]