KT-33761 Add reduceOrNull

This commit is contained in:
Alfredo Delli Bovi
2019-12-11 08:31:18 +01:00
committed by Ilya Gorbunov
parent 39e1b24c2c
commit f5d696d3c4
10 changed files with 345 additions and 0 deletions
+7
View File
@@ -1281,6 +1281,13 @@ class StringTest {
}
}
@Test fun reduceOrNull() = withOneCharSequenceArg { arg1 ->
// get the smallest character(by char value)
assertEquals('a', arg1("bacfd").reduceOrNull { v, c -> if (v > c) c else v })
expect(null, { arg1("").reduceOrNull { _, _ -> '\n' } })
}
@Test fun groupBy() = withOneCharSequenceArg("abAbaABcD") { data ->
// group characters by their case
val result = data.groupBy { it.isAsciiUpperCase() }