Scala List Filter Method

In a previous SKB, we met themapmethod that the standard library offers. There are plenty more, but let's focus on thefiltermethod in this Scala Knowledge Bit.

Thefiltermethod allows you to keep the elements of the list that return true for the test (Also called a lambda function).

For instance, forlist.filter(a => a > 2), thelistwill be filtered down to only keep the elements that are> 2(greater than 2). If the list wasList(1,2,3,4)then the filter method would return a new list:List(3,4).

Reveal more information and clues
Load Exercise