reduceRightIndexedOrNull
Accumulates value starting with the last character and applying operation from right to left to each character with its index in the original char sequence and current accumulator value.
inline fun CharSequence.reduceRightIndexedOrNull(operation: (index: Int, Char, acc: Char) -> Char): Char?(source)
fun main() {
val text = "kotlin"
// Find the character with the highest code point by scanning from right to left
val maxChar: Char? = text.reduceRightIndexedOrNull { index, current, acc ->
if (current > acc) current else acc
}
println(maxChar) // Prints: t
}