Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

filter

scala

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.

like image 691
KingOfCoders Avatar asked Dec 22 '22 22:12

KingOfCoders


1 Answers

list.view.filter(expensiveOperation).take(20).toList
like image 78
Liza Shakury Avatar answered Dec 28 '22 09:12

Liza Shakury