Gizmox Gizmox - 1 year ago 84
Scala Question

List[(Int,Int)] Into List[Int] - Seeking Advice

Ok, so iv'e done about an hour of searching can't find any realistic ways to take a list of tuple ints I.E

val e = List((5,10),(10,13),(30,37))

And without using a mutable list i want to create a new list based off the old one.... however in this new list instead of tuples i want all the integers in between the 2 values.
I.E the Above LIST into =>

Any help would be greatly appreciated.

TL:DR List of Tuples[Int,Int] into new List of values inbetween the two into ints untupled.

Answer Source
scala> val e = List((5,10),(10,13),(30,37))
e: List[(Int, Int)] = List((5,10), (10,13), (30,37))

scala> e.flatMap(t => t._1+1 until t._2)
res1: List[Int] = List(6, 7, 8, 9, 11, 12, 31, 32, 33, 34, 35, 36)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download