Reputation: 15375
I have a method that need to create Map[Integer, Data]
based on 2 Sets
. It is kind of merge for the parameters where the key in the map is the key of each tuple in the sets, and the value is Data
object constructed with the tuples values.
def craete(included: Set[(Int, Set[Int])], excluded: Set[(Int, Set[Int])]) {
//create new Map[Integer, Data]...
}
and the dataObject class:
class Data(included: Seq[Integer], excluded: Seq[Integer]) {
}
Upvotes: 0
Views: 36
Reputation: 12565
case class Data(included: Set[Int], excluded: Set[Int])
def create(included: Map[Int, Set[Int]], excluded: Map[Int, Set[Int]]): Map[Int, Data] = {
val keys = included.keySet union excluded.keySet
keys.iterator.map(id => id -> Data(
included.getOrElse(id, Set.empty),
excluded.getOrElse(id, Set.empty))
).toMap
}
Note that there is no Integer
in scala
Upvotes: 2