reduceByKey(_ ++ _) equivalent to reduceByKey((x,y)=> x ++ y) reduceByKey takes two parameters, applies a function, and returns
First, it breaks the set, and ++ simply combines the collections, combining the elements of both sets.
For each key, it is saved in the list. In your case, 1 as the key x will be List(2,3) , and y will be List (3,4) and ++ will add both as List (2,3,3,4)
If you have a different value, for example (1,4,5) , then x will be List(4,5) in this case and y should be List (2,3,3,4) , and the result will be List(2,3,3,4,4,5)
source share