Docs and samples for 'windowed' function
This commit is contained in:
@@ -917,7 +917,7 @@ public expect fun <T> Iterable<T>.chunked(size: Int): List<List<T>>
|
||||
* @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.
|
||||
* You should not store it or allow it to escape in some way, 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.
|
||||
@@ -1033,9 +1033,37 @@ public expect inline fun <T> Iterable<T>.plusElement(element: T): List<T>
|
||||
@kotlin.internal.InlineOnly
|
||||
public expect inline fun <T> Collection<T>.plusElement(element: T): List<T>
|
||||
|
||||
/**
|
||||
* Returns a list of snapshots of the window of the given [size]
|
||||
* sliding along this collection with the given [step], where each
|
||||
* snapshot is a list.
|
||||
*
|
||||
* Several last lists may have less elements than the given [size].
|
||||
*
|
||||
* Both [size] and [step] must be positive and can be greater than the number of elements in this collection.
|
||||
* @param size the number of elements to take in each window
|
||||
* @param step the number of elements to move the window forward by on an each step
|
||||
*
|
||||
* @sample samples.collections.Sequences.Transformations.takeWindows
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun <T> Iterable<T>.windowed(size: Int, step: Int): List<List<T>>
|
||||
|
||||
/**
|
||||
* Returns a list of results of applying the given [transform] function to
|
||||
* an each list representing a view over the window of the given [size]
|
||||
* sliding along this collection with the given [step].
|
||||
*
|
||||
* 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 to escape in some way, unless you made a snapshot of it.
|
||||
* Several last lists may have less elements than the given [size].
|
||||
*
|
||||
* Both [size] and [step] must be positive and can be greater than the number of elements in this collection.
|
||||
* @param size the number of elements to take in each window
|
||||
* @param step the number of elements to move the window forward by on an each step
|
||||
*
|
||||
* @sample samples.collections.Sequences.Transformations.averageWindows
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun <T, R> Iterable<T>.windowed(size: Int, step: Int, transform: (List<T>) -> R): List<R>
|
||||
|
||||
|
||||
@@ -824,7 +824,7 @@ public expect fun <T> Sequence<T>.chunked(size: Int): Sequence<List<T>>
|
||||
* @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.
|
||||
* You should not store it or allow it to escape in some way, 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.
|
||||
@@ -960,9 +960,37 @@ public expect operator fun <T> Sequence<T>.plus(elements: Sequence<T>): Sequence
|
||||
@kotlin.internal.InlineOnly
|
||||
public expect inline fun <T> Sequence<T>.plusElement(element: T): Sequence<T>
|
||||
|
||||
/**
|
||||
* Returns a sequence of snapshots of the window of the given [size]
|
||||
* sliding along this sequence with the given [step], where each
|
||||
* snapshot is a list.
|
||||
*
|
||||
* Several last lists may have less elements than the given [size].
|
||||
*
|
||||
* Both [size] and [step] must be positive and can be greater than the number of elements in this sequence.
|
||||
* @param size the number of elements to take in each window
|
||||
* @param step the number of elements to move the window forward by on an each step
|
||||
*
|
||||
* @sample samples.collections.Sequences.Transformations.takeWindows
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun <T> Sequence<T>.windowed(size: Int, step: Int): Sequence<List<T>>
|
||||
|
||||
/**
|
||||
* Returns a sequence of results of applying the given [transform] function to
|
||||
* an each list representing a view over the window of the given [size]
|
||||
* sliding along this sequence with the given [step].
|
||||
*
|
||||
* 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 to escape in some way, unless you made a snapshot of it.
|
||||
* Several last lists may have less elements than the given [size].
|
||||
*
|
||||
* Both [size] and [step] must be positive and can be greater than the number of elements in this sequence.
|
||||
* @param size the number of elements to take in each window
|
||||
* @param step the number of elements to move the window forward by on an each step
|
||||
*
|
||||
* @sample samples.collections.Sequences.Transformations.averageWindows
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun <T, R> Sequence<T>.windowed(size: Int, step: Int, transform: (List<T>) -> R): Sequence<R>
|
||||
|
||||
|
||||
@@ -657,7 +657,7 @@ public expect fun CharSequence.chunked(size: Int): List<String>
|
||||
* @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.
|
||||
* You should not store it or allow it to escape in some way, 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.
|
||||
@@ -686,7 +686,7 @@ public expect fun CharSequence.chunkedSequence(size: Int): Sequence<String>
|
||||
* @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.
|
||||
* You should not store it or allow it to escape in some way, 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.
|
||||
@@ -731,15 +731,71 @@ public expect inline fun CharSequence.partition(predicate: (Char) -> Boolean): P
|
||||
*/
|
||||
public expect inline fun String.partition(predicate: (Char) -> Boolean): Pair<String, String>
|
||||
|
||||
/**
|
||||
* Returns a list of snapshots of the window of the given [size]
|
||||
* sliding along this char sequence with the given [step], where each
|
||||
* snapshot is a string.
|
||||
*
|
||||
* Several last strings may have less characters than the given [size].
|
||||
*
|
||||
* Both [size] and [step] must be positive and can be greater than the number of elements in this char sequence.
|
||||
* @param size the number of elements to take in each window
|
||||
* @param step the number of elements to move the window forward by on an each step
|
||||
*
|
||||
* @sample samples.collections.Sequences.Transformations.takeWindows
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun CharSequence.windowed(size: Int, step: Int): List<String>
|
||||
|
||||
/**
|
||||
* Returns a list of results of applying the given [transform] function to
|
||||
* an each char sequence representing a view over the window of the given [size]
|
||||
* sliding along this char sequence with the given [step].
|
||||
*
|
||||
* 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 in some way, unless you made a snapshot of it.
|
||||
* Several last char sequences may have less characters than the given [size].
|
||||
*
|
||||
* Both [size] and [step] must be positive and can be greater than the number of elements in this char sequence.
|
||||
* @param size the number of elements to take in each window
|
||||
* @param step the number of elements to move the window forward by on an each step
|
||||
*
|
||||
* @sample samples.collections.Sequences.Transformations.averageWindows
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun <R> CharSequence.windowed(size: Int, step: Int, transform: (CharSequence) -> R): List<R>
|
||||
|
||||
/**
|
||||
* Returns a sequence of snapshots of the window of the given [size]
|
||||
* sliding along this char sequence with the given [step], where each
|
||||
* snapshot is a string.
|
||||
*
|
||||
* Several last strings may have less characters than the given [size].
|
||||
*
|
||||
* Both [size] and [step] must be positive and can be greater than the number of elements in this char sequence.
|
||||
* @param size the number of elements to take in each window
|
||||
* @param step the number of elements to move the window forward by on an each step
|
||||
*
|
||||
* @sample samples.collections.Sequences.Transformations.takeWindows
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun CharSequence.windowedSequence(size: Int, step: Int): Sequence<String>
|
||||
|
||||
/**
|
||||
* Returns a sequence of results of applying the given [transform] function to
|
||||
* an each char sequence representing a view over the window of the given [size]
|
||||
* sliding along this char sequence with the given [step].
|
||||
*
|
||||
* 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 in some way, unless you made a snapshot of it.
|
||||
* Several last char sequences may have less characters than the given [size].
|
||||
*
|
||||
* Both [size] and [step] must be positive and can be greater than the number of elements in this char sequence.
|
||||
* @param size the number of elements to take in each window
|
||||
* @param step the number of elements to move the window forward by on an each step
|
||||
*
|
||||
* @sample samples.collections.Sequences.Transformations.averageWindows
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun <R> CharSequence.windowedSequence(size: Int, step: Int, transform: (CharSequence) -> R): Sequence<R>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user