asSequence

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

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
}
Common
JVM
JS
Native
1.0
fun <T> Iterable<T>.asSequence(): Sequence<T>
(source)

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

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

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val map = mapOf(1 to "x", 2 to "y", -1 to "zz")
val sequence = map.asSequence()

println(sequence.joinToString()) // 1=x, 2=y, -1=zz
//sampleEnd
}