Improve and group samples for operations on Iterables #KT-20357

This commit is contained in:
Ilya Gorbunov
2017-11-04 00:47:41 +03:00
parent 75348dd0c0
commit e16a0ba650
3 changed files with 38 additions and 17 deletions
@@ -20,7 +20,7 @@ package kotlin.collections
/**
* Given an [iterator] function constructs an [Iterable] instance that returns values through the [Iterator]
* provided by that function.
* @sample samples.collections.Iterables.iterable
* @sample samples.collections.Iterables.Building.iterable
*/
@kotlin.internal.InlineOnly
public inline fun <T> Iterable(crossinline iterator: () -> Iterator<T>): Iterable<T> = object : Iterable<T> {
@@ -74,7 +74,7 @@ internal fun <T> Iterable<T>.convertToSetForSetOperation(): Collection<T> =
/**
* Returns a single list of all elements from all collections in the given collection.
* @sample samples.collections.Iterables.flattenIterable
* @sample samples.collections.Iterables.Operations.flattenIterable
*/
public fun <T> Iterable<Iterable<T>>.flatten(): List<T> {
val result = ArrayList<T>()
@@ -88,7 +88,7 @@ public fun <T> Iterable<Iterable<T>>.flatten(): List<T> {
* Returns a pair of lists, where
* *first* list is built from the first values of each pair from this collection,
* *second* list is built from the second values of each pair from this collection.
* @sample samples.collections.Iterables.unzipIterable
* @sample samples.collections.Iterables.Operations.unzipIterable
*/
public fun <T, R> Iterable<Pair<T, R>>.unzip(): Pair<List<T>, List<R>> {
val expectedSize = collectionSizeOrDefault(10)
@@ -35,6 +35,7 @@ public fun <T> buildSequence(builderAction: suspend SequenceBuilder<T>.() -> Uni
* Builds an [Iterator] lazily yielding values one by one.
*
* @sample samples.collections.Sequences.Building.buildIterator
* @sample samples.collections.Iterables.Building.iterable
*/
@SinceKotlin("1.1")
public fun <T> buildIterator(builderAction: suspend SequenceBuilder<T>.() -> Unit): Iterator<T> {