Reputation: 645
How to transform:
(Map(UserLang -> en, UserName -> a),1)
(Map(UserLang -> jp, UserName -> b),1)
to
(UserLang -> en, UserName -> a)
(UserLang -> jp, UserName -> b)
How to do this via functional programming
Upvotes: 1
Views: 209
Reputation: 51271
(Map(UserLang -> en, UserName -> a),1)
is type (Map[String,String], Int)
and not Map[(String,String),Int]
as stated in the question title.
For the former, try map(_._1)
. For the latter try keys.toMap
.
Upvotes: 1
Reputation: 23532
Try something like this:
val map1: Map[(String, String),Int]
val map2: Map[String, String] = map1.keySet.toMap
.keySet
discards the Int
and turns your Map[(String, String),Int]
into a Set[(String,String)]
which you can then easily convert to a Map
by calling toMap
.
Upvotes: 1