Scala: List[Tuple3] to Map[String,String]

dictionary, list, scala, tuples, type-conversion

Solution

A little more concise:

val prices =
  dao.getPricing.map { case (id, label, fee) => ( id.toString, label+" $"+fee)} toMap

shorter alternative:

val prices =
  dao.getPricing.map { p => ( p._1.toString, p._2+" $"+p._3)} toMap

Problem

I've got a query result of `List[(Int,String,Double)]` that I need to convert to a `Map[String,String]` (for display in an html select list) My hacked solution is: ``` val prices = (dao.getPricing flatMap { case(id, label, fee) => Map(id.toString -> (label+" $"+fee)) }).toMap ``` there must be a better way to achieve the same...

Original source