I have some list: List <Pet>
I need to take 3 elements from it that satisfy the condition:
I do it like this:
list.filter { g -> !mainList.contains(g) }.take(3)
How can you optimize this code so that the filter operation is executed no more than enough times for the result?