Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced zipAll() for KT-13017 #4568

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MRylander
Copy link

Adding zipAll function to address https://youtrack.jetbrains.com/issue/KT-13017

Code, docs, and samples are written to be constant with existing zip function below.

/**
* Returns a list of values built from the elements of `this` collection and the [other] array with the same index
* using the provided [transform] function applied to each pair of elements.
* The returned list has length of the shortest collection.
*
* @sample samples.collections.Iterables.Operations.zipIterableWithTransform
*/
public inline fun <T, R, V> Iterable<T>.zip(other: Array<out R>, transform: (a: T, b: R) -> V): List<V> {
val arraySize = other.size
val list = ArrayList<V>(minOf(collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in this) {
if (i >= arraySize) break
list.add(transform(element, other[i++]))
}
return list
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants