Ending filter in Scala on a List after number of successful results

Viewed 60

I have a list I want to filter, but end after a certain amount of successful items in the result. How would I do that?

My filter has an expensive operation

list.filter(expensiveOperation)

and I only need say 20 results from the list.

1 Answers
list.view.filter(expensiveOperation).take(20).toList
Related