Categories
*.JAR

Scala, берегите свои глаза

Another common kind of operation combines the elements of a list with some operator. For instance:

sum(List(a,b,c)) equals 0+a+b+c

This is a special instance of a fold operation:

  scala> def sum(xs: List[Int]): Int = (0 /: xs) (_ + _)
  sum: (xs: List[Int])Int

Similarly:

product(List(a, b, c)) equals 1 * a * b * c

is a special instance of this fold operation:

  scala> def product(xs: List[Int]): Int = (1 /: xs) (_ * _)
  product: (xs: List[Int])Int

Не знаю кем нужно быть, чтобы (1 /: xs) (_ * _) показалось хорошей идеей.