Scala: foldLeft和foldRight 实战

scala源代码:

def /:[B](z: B)(op: (B, A) => B): B = foldLeft(z)(op)
def :\[B](z: B)(op: (A, B) => B): B = foldRight(z)(op)

在scala命令行运行
scala> (0/:(1 to 100))(_+_) 
res0: Int = 5050

scala> ((1 to 100):\0)(_+_)
res1: Int = 5050

 

DT大数据微信公众账号:DT_Spark
DT大数据梦工厂scala的所有视频、PPT和代码在百度云盘的链接地址:​​​http://pan.baidu.com/share/home?uk=4013289088&view=share#category/type=0&qq-pf-to=pcqq.group​