W3cubDocs

/Kotlin

asSequence

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <T> Array<out T>.asSequence(): Sequence<T>
fun ByteArray.asSequence(): Sequence<Byte>
fun ShortArray.asSequence(): Sequence<Short>
fun IntArray.asSequence(): Sequence<Int>
fun LongArray.asSequence(): Sequence<Long>
fun FloatArray.asSequence(): Sequence<Float>
fun DoubleArray.asSequence(): Sequence<Double>
fun BooleanArray.asSequence(): Sequence<Boolean>
fun CharArray.asSequence(): Sequence<Char>

Creates a Sequence instance that wraps the original array returning its elements when being iterated.

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
}
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <T> Iterable<T>.asSequence(): Sequence<T>

Creates a Sequence instance that wraps the original collection returning its elements when being iterated.

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
}
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <K, V> Map<out K, V>.asSequence(): Sequence<Entry<K, V>>

Creates a Sequence instance that wraps the original map returning its entries when being iterated.

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/as-sequence.html