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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。