Rename sequence and iterator builder functions and their scope class

This introduces new functions instead of the existing sequence builders:
- `sequence` instead of `buildSequence`
- `iterator` instead of `buildIterator`
- `SequenceScope` instead of `SequenceBuilder`

The old functions were deprecated with error and made inline-only, and `SequenceBuilder` has been
made a deprecated typealias to `SequenceScope`.

Move sequence builders to `SequencesKt` facade class.

Replace sequence builder usages in stdlib and samples.

#KT-26678
This commit is contained in:
Ilya Gorbunov
2018-09-07 07:15:21 +03:00
parent 9c812c6e2b
commit aac96c476a
9 changed files with 56 additions and 46 deletions
@@ -26,7 +26,7 @@ class Iterables {
@Sample
fun iterable() {
val iterable = Iterable {
buildIterator {
iterator {
yield(42)
yieldAll(1..5 step 2)
}
@@ -111,7 +111,7 @@ class Sequences {
@Sample
fun buildFibonacciSequence() {
fun fibonacci() = buildSequence {
fun fibonacci() = sequence {
var terms = Pair(0, 1)
// this sequence is infinite
@@ -126,7 +126,7 @@ class Sequences {
@Sample
fun buildSequenceYieldAll() {
val sequence = buildSequence {
val sequence = sequence {
val start = 0
// yielding a single value
yield(start)
@@ -145,7 +145,7 @@ class Sequences {
val wrappedCollection = object : AbstractCollection<Any>() {
override val size: Int = collection.size + 2
override fun iterator(): Iterator<Any> = buildIterator {
override fun iterator(): Iterator<Any> = iterator {
yield("first")
yieldAll(collection)
yield("last")