Filter plus filterNot

Isn’t there a function which does a filter and filterNot with one pass, returning a tuple of the two partitions? I always guess the name of this function is partitionBy or partitionWith but that’s not the name.

scala> List(1,2,3,4,5,6).partition(_ % 2 == 0)
val res1: (List[Int], List[Int]) = (List(2, 4, 6),List(1, 3, 5))
1 Like

Thanks. I was searching for filter in the documentation for Seq, and it looks like the doc for partition does not contain the word filter.

I find a good way to search for such generic functions in the documentation is to look for the return type I expect (e.g. here searching for (Seq[ to find any tuples with Seq in it). This often works better than searching for keywords, as there aren’t as many ways to express the result in types as in natural language.

4 Likes