case class Person(name : String, age : Int) val team = List(Person("Moni", 29), Person("Anna", 30), Person("Hannes", 40)); val ages = team.map(_.age); val names = team.map(_.name); println(ages.reduce(Math.min(_,_))); println(ages.min); println(team.minBy(_.age)); println(ages.reduce(_+_) / ages.size); println(ages.sum / ages.size); println(names.reduce(_+", "+_)); println(names.mkString(", "));
Sunday, September 23, 2012
Reduce, Min, MinBy, Sum and MkString
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment