Let I have big array of some structure (in example below Int is for simplicity) and want to filter this array and take first n elements. How can I do it?
Example:
val outerVar = 22 def filterFunction(a: Int): Boolean = { if (true/* some condition into this */) return false if (a > 12) return true if (a > 750) return false if (a == 42) return true if (a == outerVar) return true // etc conditions that can use context of outer space false } val n = 42 val bigArray = Array(1, 2, 3, 4, 5) val result = bigArray.filter(element => { filterFunction(element) }) //.limit(n) (something like) // how to stop filling result after it will contain n elements?