Add sample for reduceOrNull and reduceRightOrNull

This commit is contained in:
Alfredo Delli Bovi
2019-12-13 19:17:04 +01:00
committed by Ilya Gorbunov
parent 06008c40ab
commit 9546307243
7 changed files with 82 additions and 0 deletions
@@ -641,6 +641,22 @@ class Collections {
val emptyMin = emptyList.minBy { it.length }
assertPrints(emptyMin, "null")
}
@Sample
fun reduceOrNull() {
val strings = listOf("a", "b", "c", "d")
assertPrints(strings.reduceOrNull { acc, string -> acc + string }, "abcd")
assertPrints(emptyList<String>().reduceOrNull { _, _ -> "" }, "null")
}
@Sample
fun reduceRightOrNull() {
val strings = listOf("a", "b", "c", "d")
assertPrints(strings.reduceRightOrNull { string, acc -> acc + string }, "dcba")
assertPrints(emptyList<String>().reduceRightOrNull { _, _ -> "" }, "null")
}
}
class Elements {