case class Person(name : String, site : String) val team = List( Person("Moni", "M"), Person("Anna", "M"), Person("Hannes", "N"), Person("Horst", "N")); val sites = team.groupBy(_.site); sites.foreach { case (site, persons) => println(site + ": " + persons.map(_.name).mkString(", ")); } sites.foreach { siteAndPersons => println(siteAndPersons._1 + ": " + siteAndPersons._2.map(_.name).mkString(", ")); }
Sunday, September 23, 2012
GroupBy, ForEach and Case
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment