Vandexel Vandexel - 1 year ago 66
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


Answer Source

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))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download