asSequence

fun <T> Array<out T>.asSequence(): Sequence<T>(source)

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

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val array = arrayOf('a', 'b', 'c')
val sequence = array.asSequence()

println(sequence.joinToString()) // a, b, c 
   //sampleEnd
}

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

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val collection = listOf('a', 'b', 'c')
val sequence = collection.asSequence()

println(sequence.joinToString()) // a, b, c 
   //sampleEnd
}

fun <K, V> Map<out K, V>.asSequence(): Sequence<Map.Entry<K, V>>(source)

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

Since Kotlin

1.0