Ellen Spertus
03/30/2020, 10:55 PMprintln((1..100000).map { it * it }.filter { it > 10 }.first())
(My real code doesn’t involve numbers or squaring, just a calculation that I want to stop computing when I get an acceptable result from map
.)Ellen Spertus
03/30/2020, 11:00 PMShawn
03/30/2020, 11:34 PMval firstSquareGreaterThanTen = (1..10000).asSequence()
.map { it to it * it }
.first { (_, square) -> square > 10 }
val (base, square) = firstSquareGreaterThanTen
println("base: $base, square: $square")
Ellen Spertus
03/30/2020, 11:36 PMaraqnid
03/31/2020, 6:33 AMtakeWhile
than first
🤔