Docs and samples for 'chunked' function

This commit is contained in:
Ilya Gorbunov
2017-05-16 23:53:46 +03:00
parent e418f61f0c
commit b2f2e3537b
12 changed files with 391 additions and 2 deletions
@@ -898,9 +898,32 @@ public expect fun <T : Any> Iterable<T?>.requireNoNulls(): Iterable<T>
*/
public expect fun <T : Any> List<T?>.requireNoNulls(): List<T>
/**
* Splits this collection into a list of lists each not exceeding the given [size].
*
* The last list in the resulting list may have less elements than the given [size].
*
* @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this collection.
*
* @sample samples.collections.Collections.Transformations.chunked
*/
@SinceKotlin("1.2")
public expect fun <T> Iterable<T>.chunked(size: Int): List<List<T>>
/**
* Splits this collection into several lists each not exceeding the given [size]
* and applies the given [transform] function to an each.
*
* @return list of results of the [transform] applied to an each list.
*
* Note that the list passed to the [transform] function is ephemeral and is valid only inside that function.
* You should not store it or allow it escape someway, unless you made a snapshot of it.
* The last list may have less elements than the given [size].
*
* @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this collection.
*
* @sample samples.text.Strings.chunkedTransform
*/
@SinceKotlin("1.2")
public expect fun <T, R> Iterable<T>.chunked(size: Int, transform: (List<T>) -> R): List<R>
@@ -803,9 +803,36 @@ public expect inline fun <T> Sequence<T>.sumByDouble(selector: (T) -> Double): D
*/
public expect fun <T : Any> Sequence<T?>.requireNoNulls(): Sequence<T>
/**
* Splits this sequence into a sequence of lists each not exceeding the given [size].
*
* The last list in the resulting sequence may have less elements than the given [size].
*
* @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this sequence.
*
* @sample samples.collections.Collections.Transformations.chunked
*
* The operation is _intermediate_ and _stateful_.
*/
@SinceKotlin("1.2")
public expect fun <T> Sequence<T>.chunked(size: Int): Sequence<List<T>>
/**
* Splits this sequence into several lists each not exceeding the given [size]
* and applies the given [transform] function to an each.
*
* @return sequence of results of the [transform] applied to an each list.
*
* Note that the list passed to the [transform] function is ephemeral and is valid only inside that function.
* You should not store it or allow it escape someway, unless you made a snapshot of it.
* The last list may have less elements than the given [size].
*
* @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this sequence.
*
* @sample samples.text.Strings.chunkedTransform
*
* The operation is _intermediate_ and _stateful_.
*/
@SinceKotlin("1.2")
public expect fun <T, R> Sequence<T>.chunked(size: Int, transform: (List<T>) -> R): Sequence<R>
@@ -638,15 +638,61 @@ public expect inline fun CharSequence.sumBy(selector: (Char) -> Int): Int
*/
public expect inline fun CharSequence.sumByDouble(selector: (Char) -> Double): Double
/**
* Splits this char sequence into a list of strings each not exceeding the given [size].
*
* The last string in the resulting list may have less characters than the given [size].
*
* @param size the number of elements to take in each string, must be positive and can be greater than the number of elements in this char sequence.
*
* @sample samples.collections.Collections.Transformations.chunked
*/
@SinceKotlin("1.2")
public expect fun CharSequence.chunked(size: Int): List<String>
/**
* Splits this char sequence into several char sequences each not exceeding the given [size]
* and applies the given [transform] function to an each.
*
* @return list of results of the [transform] applied to an each char sequence.
*
* Note that the char sequence passed to the [transform] function is ephemeral and is valid only inside that function.
* You should not store it or allow it escape someway, unless you made a snapshot of it.
* The last char sequence may have less characters than the given [size].
*
* @param size the number of elements to take in each char sequence, must be positive and can be greater than the number of elements in this char sequence.
*
* @sample samples.text.Strings.chunkedTransform
*/
@SinceKotlin("1.2")
public expect fun <R> CharSequence.chunked(size: Int, transform: (CharSequence) -> R): List<R>
/**
* Splits this char sequence into a sequence of strings each not exceeding the given [size].
*
* The last string in the resulting sequence may have less characters than the given [size].
*
* @param size the number of elements to take in each string, must be positive and can be greater than the number of elements in this char sequence.
*
* @sample samples.collections.Collections.Transformations.chunked
*/
@SinceKotlin("1.2")
public expect fun CharSequence.chunkedSequence(size: Int): Sequence<String>
/**
* Splits this char sequence into several char sequences each not exceeding the given [size]
* and applies the given [transform] function to an each.
*
* @return sequence of results of the [transform] applied to an each char sequence.
*
* Note that the char sequence passed to the [transform] function is ephemeral and is valid only inside that function.
* You should not store it or allow it to escape someway, unless you made a snapshot of it.
* The last char sequence may have less characters than the given [size].
*
* @param size the number of elements to take in each char sequence, must be positive and can be greater than the number of elements in this char sequence.
*
* @sample samples.text.Strings.chunkedTransformToSequence
*/
@SinceKotlin("1.2")
public expect fun <R> CharSequence.chunkedSequence(size: Int, transform: (CharSequence) -> R): Sequence<R>