Aug
20
// Sum the values in a list
val sum = (0.0 /: list){ _ + _ }
// What it says: it's an abbreviated form of
// list.leftFold(0.0) { (s,i) => s + i }
// Find the minimum value in a list
val minValue = list.reduceLeft( _ min _ )
// What it says: Note that it's reduce, not fold. It applies the
// min function to the series of results obtained by applying
// the function from the left.
// Note the difference between fold and reduce: fold takes an
// initial value, while reduce does not.
Tags: Scala