大数据Spark “蘑菇云”行动前传第22课:Scala集合和高级函数操作实战及Spark源码鉴赏.

大数据Spark “蘑菇云”行动前传第22课:Scala集合和高级函数操作实战及Spark源码鉴赏.
1 及Spark源码集合和高级函数鉴赏.
2 Scala集合和高级函数操作实战

 

 

Microsoft Windows [版本 6.1.7601]
(C) 版权所有 1985-2003 Microsoft Corp.

C:\Users\admin\Desktop>scala
Welcome to Scala version 2.10.4 (Java HotSpot(TM) Client VM, Java 1.8.0_65).
Type in expressions to have them evaluated.
Type :help for more information.

scala> (1 to 10)
res0: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8,
 9, 10)

scala> (1 to 10).re
:8: error: value re is not a member of scala.collection.immutable.Range
.Inclusive
              (1 to 10).re
                        ^

scala> (1 to 10).re:1: error: ';' expected but ')' found.
10)
  ^

res2: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8,
 9, 10)
        ^

scala> (1 to 10).re:1: error: ';' expected but ')' found.
10)
  ^

:8: error: value re is not a member of scala.collection.immutable.Range
.Inclusive
              (1 to 10).re
                        ^

scala> (1 to 10).
     | re
:9: error: value re is not a member of scala.collection.immutable.Range
.Inclusive
possible cause: maybe a semicolon is missing before `value re'?
              re
              ^

scala> (1 to 10).reduceLeft(_ - _)
res6: Int = -53

scala> (1 to 5).reduceLeft(_ - _)
res7: Int = -13

scala> (1 to 5).reduceLeft((a,b) => a-b)
res8: Int = -13

scala> (1 to 5).reduceLeft((a,b) => a)
res9: Int = 1

scala> (1 to 5).reduceLeft((a,b) => b)
res10: Int = 5
                              ^

scala> (1 to 5).reduceLeft((a,b) => {println(a + " : "+ b ); a-b })
1 : 2
-1 : 3
-4 : 4
-8 : 5
res13: Int = -13

scala> (1 to 5).reduceLeft((a,b) => {println(a + " : "+ b ); a-b })
1 : 2
-1 : 3
-4 : 4
-8 : 5
res14: Int = -13

scala> (1 to 5).reduceRight((a,b) => {println(a + " : "+ b ); a-b })
4 : 5
3 : -1
2 : 4
1 : -2
res15: Int = 3

scala>

 

大数据Spark “蘑菇云”行动前传第22课:Scala集合和高级函数操作实战及Spark源码鉴赏._第1张图片

 

 

大数据Spark “蘑菇云”行动前传第22课:Scala集合和高级函数操作实战及Spark源码鉴赏._第2张图片

大数据Spark “蘑菇云”行动前传第22课:Scala集合和高级函数操作实战及Spark源码鉴赏._第3张图片

你可能感兴趣的:(大数据蘑菇云行动)