reduceRight
inline fun ByteArray.reduceRight(
operation: (Byte, acc: Byte) -> Byte
): Byteinline fun ShortArray.reduceRight(
operation: (Short, acc: Short) -> Short
): Shortinline fun IntArray.reduceRight(
operation: (Int, acc: Int) -> Int
): Intinline fun LongArray.reduceRight(
operation: (Long, acc: Long) -> Long
): Longinline fun FloatArray.reduceRight(
operation: (Float, acc: Float) -> Float
): Floatinline fun DoubleArray.reduceRight(
operation: (Double, acc: Double) -> Double
): Doubleinline fun BooleanArray.reduceRight(
operation: (Boolean, acc: Boolean) -> Boolean
): Booleaninline fun CharArray.reduceRight(
operation: (Char, acc: Char) -> Char
): Charinline fun <S, T : S> List<T>.reduceRight(
operation: (T, acc: S) -> S
): S@ExperimentalUnsignedTypes inline fun ULongArray.reduceRight(
operation: (ULong, acc: ULong) -> ULong
): ULong@ExperimentalUnsignedTypes inline fun UByteArray.reduceRight(
operation: (UByte, acc: UByte) -> UByte
): UByte@ExperimentalUnsignedTypes inline fun UShortArray.reduceRight(
operation: (UShort, acc: UShort) -> UShort
): UShortAccumulates value starting with last element and applying operation from right to left to each element and current accumulator value.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val strings = listOf("a", "b", "c", "d")
println(strings.reduceRight { string, acc -> acc + string }) // dcba
println(strings.reduceRightIndexed { index, string, acc -> acc + string + index }) // dc2b1a0
// emptyList<Int>().reduceRight { _, _ -> 0 } // will fail
//sampleEnd
}