Introduce minByOrNull and maxByOrNull extension functions #KT-38854

This commit is contained in:
Abduqodiri Qurbonzoda
2020-06-15 23:27:28 +03:00
parent 846a7823ad
commit 194791a168
23 changed files with 801 additions and 594 deletions
@@ -6,16 +6,16 @@ val longList = listOf(1L, 2L, 3L)
// FILE: box.kt
fun box(): String {
val intListMin = intList.minBy { it } ?: -1
val intListMin = intList.minByOrNull { it } ?: -1
if (intListMin != 1) return "Fail intListMin=$intListMin"
val intListMax = intList.maxBy { it } ?: -1
val intListMax = intList.maxByOrNull { it } ?: -1
if (intListMax != 3) return "Fail intListMax=$intListMax"
val longListMin = longList.minBy { it } ?: -1
val longListMin = longList.minByOrNull { it } ?: -1
if (longListMin != 1L) return "Fail longListMin=$longListMin"
val longListMax = longList.maxBy { it } ?: -1
val longListMax = longList.maxByOrNull { it } ?: -1
if (longListMax != 3L) return "Fail longListMax=$longListMax"
return "OK"