https://kotlinlang.org logo
Title
m

moltendorf

05/15/2017, 5:31 AM
I feel there's a way to simplify this, no?
val squares = squares.dropWhile { it.area < id - it.area }.take(2)
val previous = squares.first()
val current = squares.last()
e

emmax

05/15/2017, 2:13 PM
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)
Updated example, based on feedback from group.
m

moltendorf

05/20/2017, 2:34 AM
I've been using this (feature) all the time, and yet somehow it didn't click for this specific piece of code even when I revisited it today until I came on here and noticed you responded. Sorry I disappeared after asking. Thanks so much!
👍 1