carpenter
carpenter

Reputation: 261

How to transform a map (tuple -> list) to (tuple, list)

Let's say I have a following Map:

Map((1,2,3) -> List(4, 5))

And now I would like to transform it to:

(1,2,3,List(4, 5))

How to do this functional way?

Upvotes: 1

Views: 636

Answers (2)

elm
elm

Reputation: 20435

A simple approach,

aMap.toList

Upvotes: 1

insan-e
insan-e

Reputation: 3921

val myMap = Map((1, 2, 3) -> List(4, 5))
val tuple = myMap map { case ((a, b, c), list) => (a, b, c, list) }

This will return you Iterable[(Int, Int, Int, List[Int])], that is an Iterable of your tuples of 1, 2, 3, List(4, 5) ... If that's what you need.

Upvotes: 4

Related Questions