Multiple conditions to handle using filter

I have an existing function which is filteringaccounts based in some date and then mapping it to a dataset.
Now i have to filter accounts based on another condition of type of accounts to be considered.
Existing function
def getAccounts(s:[Trans],businessDate): [Stats] = {
Now i have to add another condition to filter accounts based on some condition account starting with letter 1.
So can i do this by applying another filter in the above function.


You can filter twice, or filter once with a combined predicate:

scala 2.13.2> (1 to 10).filter(_ % 2 == 0).filter(_ > 6)
val res2: IndexedSeq[Int] = Vector(8, 10)

scala 2.13.2> (1 to 10).filter(n => n % 2 == 0 && n > 6)
val res3: IndexedSeq[Int] = Vector(8, 10)

As you can see, the final answer is the same either way.

1 Like