Paul Woitaschek
08/18/2020, 10:27 AMx.maxBy { ...}!! is x.maxByOrNull { ...}!! and that there is no replacement that throws if the result is null?Big Chungus
08/18/2020, 11:05 AMPaul Woitaschek
08/18/2020, 11:06 AMBig Chungus
08/18/2020, 11:32 AMBig Chungus
08/18/2020, 11:32 AMx.maxBy { ...}!! is redundant as it'll never return nullPaul Woitaschek
08/18/2020, 11:34 AMPaul Woitaschek
08/18/2020, 11:34 AMfun test() {
data class Person(val age: Int)
val oldestPerson: Person = listOf(Person(42), Person(12))
.maxBy { it.age }!!
}Paul Woitaschek
08/18/2020, 11:35 AM@Deprecated("Use maxByOrNull instead.", ReplaceWith("maxByOrNull(selector)"))
@DeprecatedSinceKotlin(warningSince = "1.4")
public inline fun <T, R : Comparable<R>> Iterable<T>.maxBy(selector: (T) -> R): T? {
return maxByOrNull(selector)
}Big Chungus
08/18/2020, 11:35 AMBig Chungus
08/18/2020, 11:36 AMPaul Woitaschek
08/18/2020, 11:37 AMPaul Woitaschek
08/18/2020, 11:38 AMBig Chungus
08/18/2020, 11:38 AMx.maxByOrNull { ...} ?: throw MyAwesomeError()?arekolek
08/18/2020, 1:28 PMSam Garfinkel
08/18/2020, 3:30 PMPaul Woitaschek
08/18/2020, 4:21 PM