asSequence
所在位置是kotlin.collections.asSequence
,其相關用法介紹如下。
用法一
創建一個 Sequence 實例,該實例包裝在迭代時返回其元素的原始數組。
例子:
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val array = arrayOf('a', 'b', 'c')
val sequence = array.asSequence()
println(sequence.joinToString()) // a, b, c
//sampleEnd
}
輸出:
a, b, c
用法二
創建一個 Sequence 實例,該實例包裝在迭代時返回其元素的原始集合。
例子:
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val collection = listOf('a', 'b', 'c')
val sequence = collection.asSequence()
println(sequence.joinToString()) // a, b, c
//sampleEnd
}
輸出:
a, b, c
用法三
創建一個 Sequence 實例,該實例包裝原始Map,在迭代時返回其條目。
相關用法
- Kotlin asSequence用法及代碼示例
- Kotlin associateBy用法及代碼示例
- Kotlin associateWithTo用法及代碼示例
- Kotlin associate用法及代碼示例
- Kotlin associateTo用法及代碼示例
- Kotlin asReversed用法及代碼示例
- Kotlin associateWith用法及代碼示例
- Kotlin associateByTo用法及代碼示例
- Kotlin all用法及代碼示例
- Kotlin any用法及代碼示例
- Kotlin aggregateTo用法及代碼示例
- Kotlin aggregate用法及代碼示例
- Kotlin map用法及代碼示例
- Kotlin filterNot用法及代碼示例
- Kotlin reduceRight用法及代碼示例
- Kotlin Random.Default用法及代碼示例
- Kotlin Byte.inc用法及代碼示例
- Kotlin getValue用法及代碼示例
- Kotlin Double.dec用法及代碼示例
- Kotlin windowedSequence用法及代碼示例
- Kotlin contentToString用法及代碼示例
- Kotlin groupByTo用法及代碼示例
- Kotlin commonPrefixWith用法及代碼示例
- Kotlin MatchResult.Destructured用法及代碼示例
- Kotlin Delegates.notNull用法及代碼示例
注:本文由純淨天空篩選整理自kotlinlang.org大神的英文原創作品 kotlin.collections.asSequence。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。