Introduce minByOrNull and maxByOrNull extension functions #KT-38854
This commit is contained in:
+4
-4
@@ -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"
|
||||
Reference in New Issue
Block a user