I have a map like:
val v = Map("01" -> List(34,12,14,23), "11" -> List(22,11,34))
I simply can’t find a way to sort the list items within map.
I tried like:
v.flatMap(v => v._2.sortBy(list => list._))
but seems that it does not sort list items.
Does anybody know where I am wrong?
UPDATE: Actually my List are List of tuples like List[(Object1, Object2, Object3, Object4)], I put int for simplicity. (but I think _.sorted will not work for my objects case). So I basically want to sort by one of this objects column. (for instance Object1.int)
This seems to work:
If your values are tuples, try this:
This approach will also work for classes, just say e.g.
_.sortBy(_.age).Or if you want one, merged list:
(for list of tuples):