Q:

Scala: Take List[People] and Convert it to a Map[String, List[People]]

I'm very new to Scala and am trying to figure out how to work with Collections. If I have a List[People], all of whom have names, is there a way to turn this into a Map[Person.getName, List[People]]. 
I tried 
list map (t => t.getName() -> t) toMap, 

but that only returns a Map[Name, People]. How do I do this?
Thanks in advance.

A:

groupBy will take a List[People] and transfrom it to a Map[String, List[People]] based on the "discriminator function" you provide which in this case is to select the name from Person.
scala> case class Person(name: String, age:Int)
defined class Person

scala> val people = List(Person("Alice", 42), Person("Bob", 42))
people: List[Person] = List(Person(Alice,42), Person(Bob,42))

scala> people.groupBy(p => p.name)
res0: scala.collection.immutable.Map[String,List[Person]] = Map(Bob -> List(Person(Bob,42)), Alice -> List(Person(Alice,42)))

