Move sequence interface definition to a separate file.
Merge SequnceJVM content into Sequences.
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package kotlin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sequence that returns values through its iterator. The values are evaluated lazily, and the sequence
|
||||||
|
* is potentially infinite.
|
||||||
|
*
|
||||||
|
* @param T the type of elements in the sequence.
|
||||||
|
*/
|
||||||
|
public interface Sequence<out T> {
|
||||||
|
/**
|
||||||
|
* Returns an iterator that returns the values from the sequence.
|
||||||
|
*/
|
||||||
|
public operator fun iterator(): Iterator<T>
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
@file:kotlin.jvm.JvmMultifileClass
|
|
||||||
@file:kotlin.jvm.JvmName("SequencesKt")
|
|
||||||
|
|
||||||
package kotlin
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
|
||||||
|
|
||||||
|
|
||||||
internal class ConstrainedOnceSequence<T>(sequence: Sequence<T>) : Sequence<T> {
|
|
||||||
private val sequenceRef = AtomicReference(sequence)
|
|
||||||
|
|
||||||
override fun iterator(): Iterator<T> {
|
|
||||||
val sequence = sequenceRef.getAndSet(null) ?: throw IllegalStateException("This sequence can be consumed only once.")
|
|
||||||
return sequence.iterator()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -6,18 +6,7 @@ package kotlin
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.support.AbstractIterator
|
import kotlin.support.AbstractIterator
|
||||||
|
|
||||||
/**
|
|
||||||
* A sequence that returns values through its iterator. The values are evaluated lazily, and the sequence
|
|
||||||
* is potentially infinite.
|
|
||||||
*
|
|
||||||
* @param T the type of elements in the sequence.
|
|
||||||
*/
|
|
||||||
public interface Sequence<out T> {
|
|
||||||
/**
|
|
||||||
* Returns an iterator that returns the values from the sequence.
|
|
||||||
*/
|
|
||||||
public operator fun iterator(): Iterator<T>
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a sequence that returns all elements from this iterator. The sequence is constrained to be iterated only once.
|
* Creates a sequence that returns all elements from this iterator. The sequence is constrained to be iterated only once.
|
||||||
@@ -485,6 +474,18 @@ public fun <T> Sequence<T>.constrainOnce(): Sequence<T> {
|
|||||||
return if (this is ConstrainedOnceSequence<T>) this else ConstrainedOnceSequence(this)
|
return if (this is ConstrainedOnceSequence<T>) this else ConstrainedOnceSequence(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@kotlin.jvm.JvmVersion
|
||||||
|
private class ConstrainedOnceSequence<T>(sequence: Sequence<T>) : Sequence<T> {
|
||||||
|
private val sequenceRef = java.util.concurrent.atomic.AtomicReference(sequence)
|
||||||
|
|
||||||
|
override fun iterator(): Iterator<T> {
|
||||||
|
val sequence = sequenceRef.getAndSet(null) ?: throw IllegalStateException("This sequence can be consumed only once.")
|
||||||
|
return sequence.iterator()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a sequence which invokes the function to calculate the next value on each iteration until the function returns `null`.
|
* Returns a sequence which invokes the function to calculate the next value on each iteration until the function returns `null`.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user