reduceRightIndexed
所在位置是kotlin.text.reduceRightIndexed
,其相关用法介绍如下。
用法:
inline fun CharSequence.reduceRightIndexed(
operation: (index: Int, Char, acc: Char) -> Char
): Char
从最后一个字符开始累加值,并将 operation 从右到左应用到每个字符,其索引在原始字符序列和当前累加器值中。
如果此 char 序列为空,则引发异常。如果字符序列可以按预期方式为空,请改用reduceRightIndexedOrNull。当接收器为空时,它返回null
。
例子:
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
}
输出:
dcba dc2b1a0
参数
相关用法
- Kotlin reduceRightIndexed用法及代码示例
- Kotlin reduceRightIndexedOrNull用法及代码示例
- 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用法及代码示例
注:本文由纯净天空筛选整理自kotlinlang.org大神的英文原创作品 kotlin.text.reduceRightIndexed。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。