Since I have a collection:
List(1, 3,-1, 0, 2, -4, 6)
It is easy to make it sorted as:
List(-4, -1, 0, 1, 2, 3, 6)
Then I can build a new collection by computing 6 - 3, 3 - 2, 2 - 1, 1 - 0, and so on:
for(i <- 0 to list.length -2) yield {
list(i + 1) - list(i)
}
and get the vector:
Vector(3, 1, 1, 1, 1, 3)
That is, I want to make the next element minus the current element.
But how to implement this in RDD on Spark?
I know for the collection:
List(-4, -1, 0, 1, 2, 3, 6)
There will be some sections of the collection, each section is ordered, can I do a similar operation on each section and collect the results on each section together?