Folding
scala> def sum(lst: List[Int]) = (0 /: lst) ((x,y) => x+y) sum: (List[Int])Int scala> sum(List(1,2,3,4)) res10: Int = 10
>> def sum(array) >> array.inject(0) {|sum,x| sum+x } >> end => nil >> sum([1,2,3,4]) => 10
scala> def fac(n: Int)=(1 /: (1 to n)) (_ * _) fac: (Int)Int scala> fac(4) res15: Int = 24
>> def fac(n) >> (1..n).inject(1) {|x,y| x * y } >> end => nil >> fac(4) => 24