reduceRightIndexedOrNull
所在位置是kotlin.collections.reduceRightIndexedOrNull
,其相關用法介紹如下。
用法一
inline fun <S, T : S> Array<out T>.reduceRightIndexedOrNull(
operation: (index: Int, T, acc: S) -> S
): S?
inline fun ByteArray.reduceRightIndexedOrNull(
operation: (index: Int, Byte, acc: Byte) -> Byte
): Byte?
inline fun ShortArray.reduceRightIndexedOrNull(
operation: (index: Int, Short, acc: Short) -> Short
): Short?
inline fun LongArray.reduceRightIndexedOrNull(
operation: (index: Int, Long, acc: Long) -> Long
): Long?
inline fun FloatArray.reduceRightIndexedOrNull(
operation: (index: Int, Float, acc: Float) -> Float
): Float?
inline fun DoubleArray.reduceRightIndexedOrNull(
operation: (index: Int, Double, acc: Double) -> Double
): Double?
inline fun BooleanArray.reduceRightIndexedOrNull(
operation: (index: Int, Boolean, acc: Boolean) -> Boolean
): Boolean?
inline fun CharArray.reduceRightIndexedOrNull(
operation: (index: Int, Char, acc: Char) -> Char
): Char?
@ExperimentalUnsignedTypes inline fun UIntArray.reduceRightIndexedOrNull(
operation: (index: Int, UInt, acc: UInt) -> UInt
): UInt?
@ExperimentalUnsignedTypes inline fun ULongArray.reduceRightIndexedOrNull(
operation: (index: Int, ULong, acc: ULong) -> ULong
): ULong?
@ExperimentalUnsignedTypes inline fun UByteArray.reduceRightIndexedOrNull(
operation: (index: Int, UByte, acc: UByte) -> UByte
): UByte?
@ExperimentalUnsignedTypes inline fun UShortArray.reduceRightIndexedOrNull(
operation: (index: Int, UShort, acc: UShort) -> UShort
): UShort?
從最後一個元素開始累加值,並從右到左將 operation 應用於每個元素及其在原始數組中的索引和當前累加器值。
如果數組為空,則返回 null
。
例子:
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val strings = listOf("a", "b", "c", "d")
println(strings.reduceRightOrNull { string, acc -> acc + string }) // dcba
println(strings.reduceRightIndexedOrNull { index, string, acc -> acc + string + index }) // dc2b1a0
println(emptyList<String>().reduceRightOrNull { _, _ -> "" }) // null
//sampleEnd
}
輸出:
dcba dc2b1a0 null
參數
用法二
inline fun <S, T : S> List<T>.reduceRightIndexedOrNull(
operation: (index: Int, T, acc: S) -> S
): S?
從最後一個元素開始累加值,並從右到左將 operation 應用於每個元素,其在原始列表中的索引和當前累加器值。
如果列表為空,則返回 null
。
例子:
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val strings = listOf("a", "b", "c", "d")
println(strings.reduceRightOrNull { string, acc -> acc + string }) // dcba
println(strings.reduceRightIndexedOrNull { index, string, acc -> acc + string + index }) // dc2b1a0
println(emptyList<String>().reduceRightOrNull { _, _ -> "" }) // null
//sampleEnd
}
輸出:
dcba dc2b1a0 null
參數
相關用法
- Kotlin reduceRightIndexed用法及代碼示例
- Kotlin reduceRight用法及代碼示例
- Kotlin reduceRightOrNull用法及代碼示例
- Kotlin reduceIndexed用法及代碼示例
- Kotlin reduceTo用法及代碼示例
- Kotlin reduceIndexedOrNull用法及代碼示例
- Kotlin reduce用法及代碼示例
- Kotlin reduceOrNull用法及代碼示例
- Kotlin reversed用法及代碼示例
- Kotlin replaceFirstChar用法及代碼示例
- Kotlin replace用法及代碼示例
- Kotlin runningReduceIndexed用法及代碼示例
- Kotlin rangeTo用法及代碼示例
- Kotlin runningFoldIndexed用法及代碼示例
- Kotlin runningReduce用法及代碼示例
- Kotlin runningFold用法及代碼示例
- Kotlin associateBy用法及代碼示例
- Kotlin all用法及代碼示例
- Kotlin map用法及代碼示例
- Kotlin filterNot用法及代碼示例
- Kotlin Random.Default用法及代碼示例
- Kotlin Byte.inc用法及代碼示例
- Kotlin getValue用法及代碼示例
- Kotlin Double.dec用法及代碼示例
- Kotlin windowedSequence用法及代碼示例
注:本文由純淨天空篩選整理自kotlinlang.org大神的英文原創作品 kotlin.collections.reduceRightIndexedOrNull。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。