Specify names for parameters of functional types with two or more parameters to ease lambda completion.
#KT-13826
This commit is contained in:
@@ -21,6 +21,6 @@ public interface Comparator<T> {
|
||||
@JsName("compare") fun compare(a: T, b: T): Int
|
||||
}
|
||||
|
||||
public inline fun <T> Comparator(crossinline comparison: (T, T) -> Int): Comparator<T> = object : Comparator<T> {
|
||||
public inline fun <T> Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator<T> = object : Comparator<T> {
|
||||
override fun compare(a: T, b: T): Int = comparison(a, b)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -616,7 +616,7 @@ public inline fun <T> Iterable<T>.filter(predicate: (T) -> Boolean): List<T> {
|
||||
* @param [predicate] function that takes the index of an element and the element itself
|
||||
* and returns the result of predicate evaluation on the element.
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.filterIndexed(predicate: (Int, T) -> Boolean): List<T> {
|
||||
public inline fun <T> Iterable<T>.filterIndexed(predicate: (index: Int, T) -> Boolean): List<T> {
|
||||
return filterIndexedTo(ArrayList<T>(), predicate)
|
||||
}
|
||||
|
||||
@@ -625,7 +625,7 @@ public inline fun <T> Iterable<T>.filterIndexed(predicate: (Int, T) -> Boolean):
|
||||
* @param [predicate] function that takes the index of an element and the element itself
|
||||
* and returns the result of predicate evaluation on the element.
|
||||
*/
|
||||
public inline fun <T, C : MutableCollection<in T>> Iterable<T>.filterIndexedTo(destination: C, predicate: (Int, T) -> Boolean): C {
|
||||
public inline fun <T, C : MutableCollection<in T>> Iterable<T>.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C {
|
||||
forEachIndexed { index, element ->
|
||||
if (predicate(index, element)) destination.add(element)
|
||||
}
|
||||
@@ -1207,7 +1207,7 @@ public inline fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
|
||||
* and returns the result of the transform applied to the element.
|
||||
*/
|
||||
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
|
||||
public inline fun <T, R> Iterable<T>.mapIndexed(transform: (Int, T) -> R): List<R> {
|
||||
public inline fun <T, R> Iterable<T>.mapIndexed(transform: (index: Int, T) -> R): List<R> {
|
||||
return mapIndexedTo(ArrayList<R>(collectionSizeOrDefault(10)), transform)
|
||||
}
|
||||
|
||||
@@ -1217,7 +1217,7 @@ public inline fun <T, R> Iterable<T>.mapIndexed(transform: (Int, T) -> R): List<
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*/
|
||||
public inline fun <T, R : Any> Iterable<T>.mapIndexedNotNull(transform: (Int, T) -> R?): List<R> {
|
||||
public inline fun <T, R : Any> Iterable<T>.mapIndexedNotNull(transform: (index: Int, T) -> R?): List<R> {
|
||||
return mapIndexedNotNullTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
@@ -1227,7 +1227,7 @@ public inline fun <T, R : Any> Iterable<T>.mapIndexedNotNull(transform: (Int, T)
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*/
|
||||
public inline fun <T, R : Any, C : MutableCollection<in R>> Iterable<T>.mapIndexedNotNullTo(destination: C, transform: (Int, T) -> R?): C {
|
||||
public inline fun <T, R : Any, C : MutableCollection<in R>> Iterable<T>.mapIndexedNotNullTo(destination: C, transform: (index: Int, T) -> R?): C {
|
||||
forEachIndexed { index, element -> transform(index, element)?.let { destination.add(it) } }
|
||||
return destination
|
||||
}
|
||||
@@ -1238,7 +1238,7 @@ public inline fun <T, R : Any, C : MutableCollection<in R>> Iterable<T>.mapIndex
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*/
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapIndexedTo(destination: C, transform: (Int, T) -> R): C {
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapIndexedTo(destination: C, transform: (index: Int, T) -> R): C {
|
||||
var index = 0
|
||||
for (item in this)
|
||||
destination.add(transform(index++, item))
|
||||
@@ -1405,7 +1405,7 @@ public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean): Int {
|
||||
/**
|
||||
* Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
|
||||
*/
|
||||
public inline fun <T, R> Iterable<T>.fold(initial: R, operation: (R, T) -> R): R {
|
||||
public inline fun <T, R> Iterable<T>.fold(initial: R, operation: (acc: R, T) -> R): R {
|
||||
var accumulator = initial
|
||||
for (element in this) accumulator = operation(accumulator, element)
|
||||
return accumulator
|
||||
@@ -1417,7 +1417,7 @@ public inline fun <T, R> Iterable<T>.fold(initial: R, operation: (R, T) -> R): R
|
||||
* @param [operation] function that takes the index of an element, current accumulator value
|
||||
* and the element itself, and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun <T, R> Iterable<T>.foldIndexed(initial: R, operation: (Int, R, T) -> R): R {
|
||||
public inline fun <T, R> Iterable<T>.foldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R): R {
|
||||
var index = 0
|
||||
var accumulator = initial
|
||||
for (element in this) accumulator = operation(index++, accumulator, element)
|
||||
@@ -1427,7 +1427,7 @@ public inline fun <T, R> Iterable<T>.foldIndexed(initial: R, operation: (Int, R,
|
||||
/**
|
||||
* Accumulates value starting with [initial] value and applying [operation] from right to left to each element and current accumulator value.
|
||||
*/
|
||||
public inline fun <T, R> List<T>.foldRight(initial: R, operation: (T, R) -> R): R {
|
||||
public inline fun <T, R> List<T>.foldRight(initial: R, operation: (T, acc: R) -> R): R {
|
||||
var accumulator = initial
|
||||
if (!isEmpty()) {
|
||||
val iterator = listIterator(size)
|
||||
@@ -1444,7 +1444,7 @@ public inline fun <T, R> List<T>.foldRight(initial: R, operation: (T, R) -> R):
|
||||
* @param [operation] function that takes the index of an element, the element itself
|
||||
* and current accumulator value, and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun <T, R> List<T>.foldRightIndexed(initial: R, operation: (Int, T, R) -> R): R {
|
||||
public inline fun <T, R> List<T>.foldRightIndexed(initial: R, operation: (index: Int, T, acc: R) -> R): R {
|
||||
var accumulator = initial
|
||||
if (!isEmpty()) {
|
||||
val iterator = listIterator(size)
|
||||
@@ -1469,7 +1469,7 @@ public inline fun <T> Iterable<T>.forEach(action: (T) -> Unit): Unit {
|
||||
* @param [action] function that takes the index of an element and the element itself
|
||||
* and performs the desired action on the element.
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.forEachIndexed(action: (Int, T) -> Unit): Unit {
|
||||
public inline fun <T> Iterable<T>.forEachIndexed(action: (index: Int, T) -> Unit): Unit {
|
||||
var index = 0
|
||||
for (item in this) action(index++, item)
|
||||
}
|
||||
@@ -1671,7 +1671,7 @@ public inline fun <T, C : Iterable<T>> C.onEach(action: (T) -> Unit): C {
|
||||
/**
|
||||
* Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element.
|
||||
*/
|
||||
public inline fun <S, T: S> Iterable<T>.reduce(operation: (S, T) -> S): S {
|
||||
public inline fun <S, T: S> Iterable<T>.reduce(operation: (acc: S, T) -> S): S {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty collection can't be reduced.")
|
||||
var accumulator: S = iterator.next()
|
||||
@@ -1687,7 +1687,7 @@ public inline fun <S, T: S> Iterable<T>.reduce(operation: (S, T) -> S): S {
|
||||
* @param [operation] function that takes the index of an element, current accumulator value
|
||||
* and the element itself and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun <S, T: S> Iterable<T>.reduceIndexed(operation: (Int, S, T) -> S): S {
|
||||
public inline fun <S, T: S> Iterable<T>.reduceIndexed(operation: (index: Int, acc: S, T) -> S): S {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty collection can't be reduced.")
|
||||
var index = 1
|
||||
@@ -1701,7 +1701,7 @@ public inline fun <S, T: S> Iterable<T>.reduceIndexed(operation: (Int, S, T) ->
|
||||
/**
|
||||
* Accumulates value starting with last element and applying [operation] from right to left to each element and current accumulator value.
|
||||
*/
|
||||
public inline fun <S, T: S> List<T>.reduceRight(operation: (T, S) -> S): S {
|
||||
public inline fun <S, T: S> List<T>.reduceRight(operation: (T, acc: S) -> S): S {
|
||||
val iterator = listIterator(size)
|
||||
if (!iterator.hasPrevious())
|
||||
throw UnsupportedOperationException("Empty list can't be reduced.")
|
||||
@@ -1718,7 +1718,7 @@ public inline fun <S, T: S> List<T>.reduceRight(operation: (T, S) -> S): S {
|
||||
* @param [operation] function that takes the index of an element, the element itself
|
||||
* and current accumulator value, and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun <S, T: S> List<T>.reduceRightIndexed(operation: (Int, T, S) -> S): S {
|
||||
public inline fun <S, T: S> List<T>.reduceRightIndexed(operation: (index: Int, T, acc: S) -> S): S {
|
||||
val iterator = listIterator(size)
|
||||
if (!iterator.hasPrevious())
|
||||
throw UnsupportedOperationException("Empty list can't be reduced.")
|
||||
@@ -1957,7 +1957,7 @@ public infix fun <T, R> Iterable<T>.zip(other: Array<out R>): List<Pair<T, R>> {
|
||||
/**
|
||||
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
|
||||
*/
|
||||
public inline fun <T, R, V> Iterable<T>.zip(other: Array<out R>, transform: (T, R) -> V): List<V> {
|
||||
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
|
||||
@@ -1978,7 +1978,7 @@ public infix fun <T, R> Iterable<T>.zip(other: Iterable<R>): List<Pair<T, R>> {
|
||||
/**
|
||||
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
|
||||
*/
|
||||
public inline fun <T, R, V> Iterable<T>.zip(other: Iterable<R>, transform: (T, R) -> V): List<V> {
|
||||
public inline fun <T, R, V> Iterable<T>.zip(other: Iterable<R>, transform: (a: T, b: R) -> V): List<V> {
|
||||
val first = iterator()
|
||||
val second = other.iterator()
|
||||
val list = ArrayList<V>(minOf(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10)))
|
||||
|
||||
@@ -312,7 +312,7 @@ public fun <T> Sequence<T>.filter(predicate: (T) -> Boolean): Sequence<T> {
|
||||
* @param [predicate] function that takes the index of an element and the element itself
|
||||
* and returns the result of predicate evaluation on the element.
|
||||
*/
|
||||
public fun <T> Sequence<T>.filterIndexed(predicate: (Int, T) -> Boolean): Sequence<T> {
|
||||
public fun <T> Sequence<T>.filterIndexed(predicate: (index: Int, T) -> Boolean): Sequence<T> {
|
||||
// TODO: Rewrite with generalized MapFilterIndexingSequence
|
||||
return TransformingSequence(FilteringSequence(IndexingSequence(this), true, { predicate(it.index, it.value) }), { it.value })
|
||||
}
|
||||
@@ -322,7 +322,7 @@ public fun <T> Sequence<T>.filterIndexed(predicate: (Int, T) -> Boolean): Sequen
|
||||
* @param [predicate] function that takes the index of an element and the element itself
|
||||
* and returns the result of predicate evaluation on the element.
|
||||
*/
|
||||
public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterIndexedTo(destination: C, predicate: (Int, T) -> Boolean): C {
|
||||
public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C {
|
||||
forEachIndexed { index, element ->
|
||||
if (predicate(index, element)) destination.add(element)
|
||||
}
|
||||
@@ -670,7 +670,7 @@ public fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R> {
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*/
|
||||
public fun <T, R> Sequence<T>.mapIndexed(transform: (Int, T) -> R): Sequence<R> {
|
||||
public fun <T, R> Sequence<T>.mapIndexed(transform: (index: Int, T) -> R): Sequence<R> {
|
||||
return TransformingIndexedSequence(this, transform)
|
||||
}
|
||||
|
||||
@@ -680,7 +680,7 @@ public fun <T, R> Sequence<T>.mapIndexed(transform: (Int, T) -> R): Sequence<R>
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*/
|
||||
public fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (Int, T) -> R?): Sequence<R> {
|
||||
public fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (index: Int, T) -> R?): Sequence<R> {
|
||||
return TransformingIndexedSequence(this, transform).filterNotNull()
|
||||
}
|
||||
|
||||
@@ -690,7 +690,7 @@ public fun <T, R : Any> Sequence<T>.mapIndexedNotNull(transform: (Int, T) -> R?)
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*/
|
||||
public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndexedNotNullTo(destination: C, transform: (Int, T) -> R?): C {
|
||||
public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndexedNotNullTo(destination: C, transform: (index: Int, T) -> R?): C {
|
||||
forEachIndexed { index, element -> transform(index, element)?.let { destination.add(it) } }
|
||||
return destination
|
||||
}
|
||||
@@ -701,7 +701,7 @@ public inline fun <T, R : Any, C : MutableCollection<in R>> Sequence<T>.mapIndex
|
||||
* @param [transform] function that takes the index of an element and the element itself
|
||||
* and returns the result of the transform applied to the element.
|
||||
*/
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(destination: C, transform: (Int, T) -> R): C {
|
||||
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(destination: C, transform: (index: Int, T) -> R): C {
|
||||
var index = 0
|
||||
for (item in this)
|
||||
destination.add(transform(index++, item))
|
||||
@@ -817,7 +817,7 @@ public inline fun <T> Sequence<T>.count(predicate: (T) -> Boolean): Int {
|
||||
/**
|
||||
* Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
|
||||
*/
|
||||
public inline fun <T, R> Sequence<T>.fold(initial: R, operation: (R, T) -> R): R {
|
||||
public inline fun <T, R> Sequence<T>.fold(initial: R, operation: (acc: R, T) -> R): R {
|
||||
var accumulator = initial
|
||||
for (element in this) accumulator = operation(accumulator, element)
|
||||
return accumulator
|
||||
@@ -829,7 +829,7 @@ public inline fun <T, R> Sequence<T>.fold(initial: R, operation: (R, T) -> R): R
|
||||
* @param [operation] function that takes the index of an element, current accumulator value
|
||||
* and the element itself, and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun <T, R> Sequence<T>.foldIndexed(initial: R, operation: (Int, R, T) -> R): R {
|
||||
public inline fun <T, R> Sequence<T>.foldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R): R {
|
||||
var index = 0
|
||||
var accumulator = initial
|
||||
for (element in this) accumulator = operation(index++, accumulator, element)
|
||||
@@ -848,7 +848,7 @@ public inline fun <T> Sequence<T>.forEach(action: (T) -> Unit): Unit {
|
||||
* @param [action] function that takes the index of an element and the element itself
|
||||
* and performs the desired action on the element.
|
||||
*/
|
||||
public inline fun <T> Sequence<T>.forEachIndexed(action: (Int, T) -> Unit): Unit {
|
||||
public inline fun <T> Sequence<T>.forEachIndexed(action: (index: Int, T) -> Unit): Unit {
|
||||
var index = 0
|
||||
for (item in this) action(index++, item)
|
||||
}
|
||||
@@ -1053,7 +1053,7 @@ public fun <T> Sequence<T>.onEach(action: (T) -> Unit): Sequence<T> {
|
||||
/**
|
||||
* Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element.
|
||||
*/
|
||||
public inline fun <S, T: S> Sequence<T>.reduce(operation: (S, T) -> S): S {
|
||||
public inline fun <S, T: S> Sequence<T>.reduce(operation: (acc: S, T) -> S): S {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty sequence can't be reduced.")
|
||||
var accumulator: S = iterator.next()
|
||||
@@ -1069,7 +1069,7 @@ public inline fun <S, T: S> Sequence<T>.reduce(operation: (S, T) -> S): S {
|
||||
* @param [operation] function that takes the index of an element, current accumulator value
|
||||
* and the element itself and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun <S, T: S> Sequence<T>.reduceIndexed(operation: (Int, S, T) -> S): S {
|
||||
public inline fun <S, T: S> Sequence<T>.reduceIndexed(operation: (index: Int, acc: S, T) -> S): S {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty sequence can't be reduced.")
|
||||
var index = 1
|
||||
@@ -1255,7 +1255,7 @@ 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.
|
||||
*/
|
||||
public fun <T, R, V> Sequence<T>.zip(other: Sequence<R>, transform: (T, R) -> V): Sequence<V> {
|
||||
public fun <T, R, V> Sequence<T>.zip(other: Sequence<R>, transform: (a: T, b: R) -> V): Sequence<V> {
|
||||
return MergingSequence(this, other, transform)
|
||||
}
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ public inline fun String.filter(predicate: (Char) -> Boolean): String {
|
||||
* @param [predicate] function that takes the index of a character and the character itself
|
||||
* and returns the result of predicate evaluation on the character.
|
||||
*/
|
||||
public inline fun CharSequence.filterIndexed(predicate: (Int, Char) -> Boolean): CharSequence {
|
||||
public inline fun CharSequence.filterIndexed(predicate: (index: Int, Char) -> Boolean): CharSequence {
|
||||
return filterIndexedTo(StringBuilder(), predicate)
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ public inline fun CharSequence.filterIndexed(predicate: (Int, Char) -> Boolean):
|
||||
* @param [predicate] function that takes the index of a character and the character itself
|
||||
* and returns the result of predicate evaluation on the character.
|
||||
*/
|
||||
public inline fun String.filterIndexed(predicate: (Int, Char) -> Boolean): String {
|
||||
public inline fun String.filterIndexed(predicate: (index: Int, Char) -> Boolean): String {
|
||||
return filterIndexedTo(StringBuilder(), predicate).toString()
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ public inline fun String.filterIndexed(predicate: (Int, Char) -> Boolean): Strin
|
||||
* @param [predicate] function that takes the index of a character and the character itself
|
||||
* and returns the result of predicate evaluation on the character.
|
||||
*/
|
||||
public inline fun <C : Appendable> CharSequence.filterIndexedTo(destination: C, predicate: (Int, Char) -> Boolean): C {
|
||||
public inline fun <C : Appendable> CharSequence.filterIndexedTo(destination: C, predicate: (index: Int, Char) -> Boolean): C {
|
||||
forEachIndexed { index, element ->
|
||||
if (predicate(index, element)) destination.append(element)
|
||||
}
|
||||
@@ -727,7 +727,7 @@ public inline fun <R> CharSequence.map(transform: (Char) -> R): List<R> {
|
||||
* @param [transform] function that takes the index of a character and the character itself
|
||||
* and returns the result of the transform applied to the character.
|
||||
*/
|
||||
public inline fun <R> CharSequence.mapIndexed(transform: (Int, Char) -> R): List<R> {
|
||||
public inline fun <R> CharSequence.mapIndexed(transform: (index: Int, Char) -> R): List<R> {
|
||||
return mapIndexedTo(ArrayList<R>(length), transform)
|
||||
}
|
||||
|
||||
@@ -737,7 +737,7 @@ public inline fun <R> CharSequence.mapIndexed(transform: (Int, Char) -> R): List
|
||||
* @param [transform] function that takes the index of a character and the character itself
|
||||
* and returns the result of the transform applied to the character.
|
||||
*/
|
||||
public inline fun <R : Any> CharSequence.mapIndexedNotNull(transform: (Int, Char) -> R?): List<R> {
|
||||
public inline fun <R : Any> CharSequence.mapIndexedNotNull(transform: (index: Int, Char) -> R?): List<R> {
|
||||
return mapIndexedNotNullTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
@@ -747,7 +747,7 @@ public inline fun <R : Any> CharSequence.mapIndexedNotNull(transform: (Int, Char
|
||||
* @param [transform] function that takes the index of a character and the character itself
|
||||
* and returns the result of the transform applied to the character.
|
||||
*/
|
||||
public inline fun <R : Any, C : MutableCollection<in R>> CharSequence.mapIndexedNotNullTo(destination: C, transform: (Int, Char) -> R?): C {
|
||||
public inline fun <R : Any, C : MutableCollection<in R>> CharSequence.mapIndexedNotNullTo(destination: C, transform: (index: Int, Char) -> R?): C {
|
||||
forEachIndexed { index, element -> transform(index, element)?.let { destination.add(it) } }
|
||||
return destination
|
||||
}
|
||||
@@ -758,7 +758,7 @@ public inline fun <R : Any, C : MutableCollection<in R>> CharSequence.mapIndexed
|
||||
* @param [transform] function that takes the index of a character and the character itself
|
||||
* and returns the result of the transform applied to the character.
|
||||
*/
|
||||
public inline fun <R, C : MutableCollection<in R>> CharSequence.mapIndexedTo(destination: C, transform: (Int, Char) -> R): C {
|
||||
public inline fun <R, C : MutableCollection<in R>> CharSequence.mapIndexedTo(destination: C, transform: (index: Int, Char) -> R): C {
|
||||
var index = 0
|
||||
for (item in this)
|
||||
destination.add(transform(index++, item))
|
||||
@@ -843,7 +843,7 @@ public inline fun CharSequence.count(predicate: (Char) -> Boolean): Int {
|
||||
/**
|
||||
* Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each character.
|
||||
*/
|
||||
public inline fun <R> CharSequence.fold(initial: R, operation: (R, Char) -> R): R {
|
||||
public inline fun <R> CharSequence.fold(initial: R, operation: (acc: R, Char) -> R): R {
|
||||
var accumulator = initial
|
||||
for (element in this) accumulator = operation(accumulator, element)
|
||||
return accumulator
|
||||
@@ -855,7 +855,7 @@ public inline fun <R> CharSequence.fold(initial: R, operation: (R, Char) -> R):
|
||||
* @param [operation] function that takes the index of a character, current accumulator value
|
||||
* and the character itself, and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun <R> CharSequence.foldIndexed(initial: R, operation: (Int, R, Char) -> R): R {
|
||||
public inline fun <R> CharSequence.foldIndexed(initial: R, operation: (index: Int, acc: R, Char) -> R): R {
|
||||
var index = 0
|
||||
var accumulator = initial
|
||||
for (element in this) accumulator = operation(index++, accumulator, element)
|
||||
@@ -865,7 +865,7 @@ public inline fun <R> CharSequence.foldIndexed(initial: R, operation: (Int, R, C
|
||||
/**
|
||||
* Accumulates value starting with [initial] value and applying [operation] from right to left to each character and current accumulator value.
|
||||
*/
|
||||
public inline fun <R> CharSequence.foldRight(initial: R, operation: (Char, R) -> R): R {
|
||||
public inline fun <R> CharSequence.foldRight(initial: R, operation: (Char, acc: R) -> R): R {
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
@@ -880,7 +880,7 @@ public inline fun <R> CharSequence.foldRight(initial: R, operation: (Char, R) ->
|
||||
* @param [operation] function that takes the index of a character, the character itself
|
||||
* and current accumulator value, and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun <R> CharSequence.foldRightIndexed(initial: R, operation: (Int, Char, R) -> R): R {
|
||||
public inline fun <R> CharSequence.foldRightIndexed(initial: R, operation: (index: Int, Char, acc: R) -> R): R {
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
@@ -902,7 +902,7 @@ public inline fun CharSequence.forEach(action: (Char) -> Unit): Unit {
|
||||
* @param [action] function that takes the index of a character and the character itself
|
||||
* and performs the desired action on the character.
|
||||
*/
|
||||
public inline fun CharSequence.forEachIndexed(action: (Int, Char) -> Unit): Unit {
|
||||
public inline fun CharSequence.forEachIndexed(action: (index: Int, Char) -> Unit): Unit {
|
||||
var index = 0
|
||||
for (item in this) action(index++, item)
|
||||
}
|
||||
@@ -1022,7 +1022,7 @@ public inline fun <S : CharSequence> S.onEach(action: (Char) -> Unit): S {
|
||||
/**
|
||||
* Accumulates value starting with the first character and applying [operation] from left to right to current accumulator value and each character.
|
||||
*/
|
||||
public inline fun CharSequence.reduce(operation: (Char, Char) -> Char): Char {
|
||||
public inline fun CharSequence.reduce(operation: (acc: Char, Char) -> Char): Char {
|
||||
if (isEmpty())
|
||||
throw UnsupportedOperationException("Empty char sequence can't be reduced.")
|
||||
var accumulator = this[0]
|
||||
@@ -1038,7 +1038,7 @@ public inline fun CharSequence.reduce(operation: (Char, Char) -> Char): Char {
|
||||
* @param [operation] function that takes the index of a character, current accumulator value
|
||||
* and the character itself and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun CharSequence.reduceIndexed(operation: (Int, Char, Char) -> Char): Char {
|
||||
public inline fun CharSequence.reduceIndexed(operation: (index: Int, acc: Char, Char) -> Char): Char {
|
||||
if (isEmpty())
|
||||
throw UnsupportedOperationException("Empty char sequence can't be reduced.")
|
||||
var accumulator = this[0]
|
||||
@@ -1051,7 +1051,7 @@ public inline fun CharSequence.reduceIndexed(operation: (Int, Char, Char) -> Cha
|
||||
/**
|
||||
* Accumulates value starting with last character and applying [operation] from right to left to each character and current accumulator value.
|
||||
*/
|
||||
public inline fun CharSequence.reduceRight(operation: (Char, Char) -> Char): Char {
|
||||
public inline fun CharSequence.reduceRight(operation: (Char, acc: Char) -> Char): Char {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty char sequence can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
@@ -1067,7 +1067,7 @@ public inline fun CharSequence.reduceRight(operation: (Char, Char) -> Char): Cha
|
||||
* @param [operation] function that takes the index of a character, the character itself
|
||||
* and current accumulator value, and calculates the next accumulator value.
|
||||
*/
|
||||
public inline fun CharSequence.reduceRightIndexed(operation: (Int, Char, Char) -> Char): Char {
|
||||
public inline fun CharSequence.reduceRightIndexed(operation: (index: Int, Char, acc: Char) -> Char): Char {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty char sequence can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
@@ -1146,7 +1146,7 @@ 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.
|
||||
*/
|
||||
public inline fun <V> CharSequence.zip(other: CharSequence, transform: (Char, Char) -> V): List<V> {
|
||||
public inline fun <V> CharSequence.zip(other: CharSequence, transform: (a: Char, b: Char) -> V): List<V> {
|
||||
val length = minOf(this.length, other.length)
|
||||
val list = ArrayList<V>(length)
|
||||
for (i in 0..length-1) {
|
||||
|
||||
Reference in New Issue
Block a user