https://kotlinlang.org logo
#stdlib
Title
# stdlib
e

elect

02/21/2020, 12:00 PM
I find myself usually finding an item by a variable and then return the variable itself, ie: `
Copy code
items.list.filter { .. }.maxBy { it.depth }?.depth ?: -1
what about providing a
maxOf((E)->T)
?
i

ilya.gorbunov

02/21/2020, 12:44 PM
We have it planned, but currently we're waiting for the compiler feature that would allow overloading on lambda return value.
👍 4
e

elect

02/21/2020, 12:45 PM
anything where I can follow the progress?
youtracke issue or similar?
z

Zach Klippenstein (he/him) [MOD]

02/21/2020, 2:57 PM
.map { it.depth }.max()
?
👍 1
@ilya.gorbunov What would that compiler feature be necessary for? You can already write that operator now:
Copy code
fun <E, T : Comparable<T>> List<E>.maxOf(mapper: (E) -> T): T? = map(mapper).max()
Or did I misunderstand what the operator would actually do?
i

ilya.gorbunov

02/21/2020, 6:35 PM
Overloads may be required for Double and Float to handle NaNs correctly.
z

Zach Klippenstein (he/him) [MOD]

02/21/2020, 6:35 PM
Ah, of course.
3 Views