Vandexel Vandexel - 8 months ago 40
Scala Question

Using scala's filter on a list of pairs

I am trying to filter a list that contains pairs.

For example my list is


I want to use filter to filter the list to only contain answers where the first number in the pair is greater than the second. How can I do this?

So, The resulting list would be



Filter for first number in pair is greater than second:

val ls = List((1,2),(3,4),(4,5),(6,2)) 
ls.filter(pair => pair._1 > pair._2) // List((6, 2))