flatten
Returns a sequence of all elements from all sequences in this sequence.
The operation is intermediate and stateless.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
//sampleStart
val sequence: Sequence<Int> = generateSequence(1) { it + 1 }
val sequenceOfSequences: Sequence<Sequence<Int>> = sequence.map { number ->
generateSequence { number }.take(number)
}
println(sequenceOfSequences.flatten().take(10).toList()) // [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
//sampleEnd
}
Returns a sequence of all elements from all iterables in this sequence.
The operation is intermediate and stateless.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
//sampleStart
val sequence: Sequence<String> = sequenceOf("123", "45")
val sequenceOfLists: Sequence<List<Char>> = sequence.map { it.toList() }
println(sequenceOfLists.flatten().toList()) // [1, 2, 3, 4, 5]
//sampleEnd
}
Returns a sequence of all elements from all sequences in this sequence.
The operation is intermediate and stateless.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val sequence: Sequence<Int> = generateSequence(1) { it + 1 }
val sequenceOfSequences: Sequence<Sequence<Int>> = sequence.map { number ->
generateSequence { number }.take(number)
}
println(sequenceOfSequences.flatten().take(10).toList()) // [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
//sampleEnd
}
Returns a sequence of all elements from all iterables in this sequence.
The operation is intermediate and stateless.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val sequence: Sequence<String> = sequenceOf("123", "45")
val sequenceOfLists: Sequence<List<Char>> = sequence.map { it.toList() }
println(sequenceOfLists.flatten().toList()) // [1, 2, 3, 4, 5]
//sampleEnd
}