I find myself usually finding an item by a variabl...
# stdlib
e
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
We have it planned, but currently we're waiting for the compiler feature that would allow overloading on lambda return value.
👍 4
e
anything where I can follow the progress?
youtracke issue or similar?
z
.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
Overloads may be required for Double and Float to handle NaNs correctly.
z
Ah, of course.