rdd.flatMap (х => x.to (3)) работает следующим образом:
1. rdd.map(x => x.to(3))
a) fetch the first element of {1, 2, 3, 3}, that is 1
b) apply to x => x.to(3), that is 1.to(3),
that is also explained as 1 to 3, it will generate the range {1, 2, 3}
c) fetch the second element of {1, 2, 3, 3}, that is 2
d) apply to x => x.to(3), that is 2.to(3), that is also explained as 2 to 3,
it will generate the range {2, 3}
e) repeat above, 3 to 3 will get {3}, the final 3 will get {3}
f) so finally, you get {{1, 2, 3}, {2, 3}, {3}, {3}}
2. flatMap is combination of map and flattern
so flatmap will make {{1, 2, 3}, {2, 3}, {3}, {3}} become {1, 2, 3, 2, 3, 3, 3}
Итак, x.to (у) только для создания диапазона, [х, у], то может использовать repl для его проверки.
C:\Windows\System32>scala
Welcome to Scala version 2.10.6 (Java HotSpot(TM) Client VM, Java 1.7.0_55).
Type in expressions to have them evaluated.
Type :help for more information.
scala> 2 to 5
res0: scala.collection.immutable.Range.Inclusive = Range(2, 3, 4, 5)
'x.to (3)' производит диапазон чисел между 'x' и' 3'. Например. '1.to (3)' is '1, 2, 3',' 2.to (3) 'is' 2, 3' и '3.to (3)' is '3'. –