総和と総積

ほー。

scala> (1 to 10).foldLeft(0)(_ + _)
res52: Int = 55

scala> (0 /: (1 to 10))(_ + _)
res53: Int = 55

scala> (1 to 10).foldLeft(1)(_ * _)
res54: Int = 3628800

scala> (1 /: (1 to 10))(_ * _)
res55: Int = 3628800
  • 追記
scala> 1 to 10 reduceLeft(_ + _)
res16: Int = 55

scala> 1 to 10 reduceLeft(_ * _)
res17: Int = 3628800