1. 程式人生 > >Spark RDD Actions操作之reduce()

Spark RDD Actions操作之reduce()

textFile.map(line => line.split(" ").size).reduce((a, b) => if (a > b) a else b)

The arguments to reduce() are Scala function literals (closures)。

reduceRDD中元素兩兩傳遞給輸入函式? 同時產生一個新的值,新產生的值與RDD中下一個元素再被傳遞給輸入函式直到最後只有一個值為止。

Scala的anonymous(匿名函式):

def num(x: Int, y: Int) => if(x > y) x else y

Scala的currying(柯里化):

def num(x: Int)(y: Int) => if(x > y) x else y

def num(x: Int) = (y: Int) => if(x > y) x else y