.filter()
calls SC-P1009Certain Scala collections support methods such as .filter
, allowing you to select elements from your collection based on specified conditions. Since each filter
call iterates through the entire collection, it is recommended that you combine/chain such consecutive calls to avoid re-iterations.
val filteredElements = elements.filter(x => x % 2 == 0).filter(x => x >= 4)
val filteredElements = elements.filter(x => x % 2 == 0 && x >= 4)