// 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.
Bookmark and Share

Tags:

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>