Add samples for zip on sequences and strings

This commit is contained in:
Ilya Gorbunov
2018-04-19 21:16:11 +03:00
parent 2d4e591b5d
commit 0eae27e03f
5 changed files with 48 additions and 0 deletions
@@ -1559,6 +1559,8 @@ public fun <T, R> Sequence<T>.windowed(size: Int, step: Int = 1, partialWindows:
/**
* Returns a sequence of pairs built from elements of both sequences with same indexes.
* Resulting sequence has length of shortest input sequence.
*
* @sample samples.collections.Sequences.Transformations.zip
*
* The operation is _intermediate_ and _stateless_.
*/
@@ -1568,6 +1570,8 @@ public infix fun <T, R> Sequence<T>.zip(other: Sequence<R>): Sequence<Pair<T, R>
/**
* Returns a sequence of values built from elements of both collections with same indexes using provided [transform]. Resulting sequence has length of shortest input sequences.
*
* @sample samples.collections.Sequences.Transformations.zipWithTransform
*
* The operation is _intermediate_ and _stateless_.
*/
@@ -1313,6 +1313,8 @@ public fun <R> CharSequence.windowedSequence(size: Int, step: Int = 1, partialWi
/**
* Returns a list of pairs built from characters of both char sequences with same indexes. List has length of shortest char sequence.
*
* @sample samples.text.Strings.zip
*/
public infix fun CharSequence.zip(other: CharSequence): List<Pair<Char, Char>> {
return zip(other) { c1, c2 -> c1 to c2 }
@@ -1320,6 +1322,8 @@ public infix fun CharSequence.zip(other: CharSequence): List<Pair<Char, Char>> {
/**
* Returns a list of values built from characters of both char sequences with same indexes using provided [transform]. List has length of shortest char sequence.
*
* @sample samples.text.Strings.zipWithTransform
*/
public inline fun <V> CharSequence.zip(other: CharSequence, transform: (a: Char, b: Char) -> V): List<V> {
val length = minOf(this.length, other.length)