Reputation: 7585
I'm trying to map some data looking like this: ("en",(20340,302))
(so a tuple of a string and a tuple: (String, (Int, Int))
) into data looking like this: (String, Int/Int)
(so the example output would be ("en", 67 )
). What is the syntax for this?
val new = old.map(a,(b,c) => (a, b/c) )
is what I tried to do, is not working though.
Upvotes: 2
Views: 4132
Reputation: 37852
val new = old.map { case (a,(b,c)) => (a, b/c) }
Which is syntactic sugar for:
val new = old.map(t => t match {
case (a,(b,c)) => (a, b/c)
})
or an uglier version:
val new = old.map(t => (t._1, t._2._1/t._2._2))
Upvotes: 3