Thread
#stdlib
    e

    elect

    2 years ago
    I find myself usually finding an item by a variable and then return the variable itself, ie: `
    items.list.filter { .. }.maxBy { it.depth }?.depth ?: -1
    what about providing a
    maxOf((E)->T)
    ?
    ilya.gorbunov

    ilya.gorbunov

    2 years ago
    We have it planned, but currently we're waiting for the compiler feature that would allow overloading on lambda return value.
    e

    elect

    2 years ago
    anything where I can follow the progress?
    youtracke issue or similar?
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    .map { it.depth }.max()
    ?
    @ilya.gorbunov What would that compiler feature be necessary for? You can already write that operator now:
    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?
    ilya.gorbunov

    ilya.gorbunov

    2 years ago
    Overloads may be required for Double and Float to handle NaNs correctly.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    Ah, of course.