I feel there's a way to simplify this, no? ```val ...
# getting-started
e
I feel there's a way to simplify this, no?
Copy code
val squares = squares.dropWhile { it.area < id - it.area }.take(2)
val previous = squares.first()
val current = squares.last()
1 reply moltendorf: Assuming the squares lambda works as you expect, you could inline declaration and initialization of previous and current like
val(previous, current) = squares.dropWhile { it.area < id - it.area }.take(2)
I prototyped a working example
Copy code
val(first, last) = listOf(1,2,3,4).filter{ it % 2 == 0 }.take(2)
    println (first) --> 2
    println (last) --> 4