Use templating in the docs for generated code to name things properly.

This commit is contained in:
Ilya Gorbunov
2015-10-24 07:22:05 +03:00
parent 5b055ac663
commit b4b84a38d5
14 changed files with 771 additions and 734 deletions
File diff suppressed because it is too large Load Diff
+12 -11
View File
@@ -147,7 +147,7 @@ public fun <T> List<T>.elementAtOrNull(index: Int): T? {
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean): T? {
return firstOrNull(predicate)
@@ -980,7 +980,7 @@ public inline fun <T, K> Iterable<T>.toMap(selector: (T) -> K): Map<K, T> {
}
/**
* Returns Map containing the values provided by [transform] and indexed by [selector] from the given collection.
* Returns Map containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given collection.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public inline fun <T, K, V> Iterable<T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
@@ -993,7 +993,8 @@ public inline fun <T, K, V> Iterable<T>.toMap(selector: (T) -> K, transform: (T)
}
/**
* Returns Map containing the values from the given collection indexed by [selector].
* Returns Map containing the elements from the given collection indexed by the key
* returned from [selector] function applied to each element.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public inline fun <T, K> Iterable<T>.toMapBy(selector: (T) -> K): Map<K, T> {
@@ -1064,14 +1065,14 @@ public inline fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
}
/**
* Returns a list containing the results of applying the given [transform] function to each element and its index of the original collection.
* Returns a list containing the results of applying the given [transform] function to each element and its index in the original collection.
*/
public inline fun <T, R> Iterable<T>.mapIndexed(transform: (Int, T) -> R): List<R> {
return mapIndexedTo(ArrayList<R>(collectionSizeOrDefault(10)), transform)
}
/**
* Appends transformed elements and their indices of the original collection using the given [transform] function
* Appends transformed elements and their indices in the original collection using the given [transform] function
* to the given [destination].
*/
public inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapIndexedTo(destination: C, transform: (Int, T) -> R): C {
@@ -1310,7 +1311,7 @@ public inline fun <R : Comparable<R>, T : Any> Iterable<T>.minBy(f: (T) -> R): T
}
/**
* Returns `true` if collection has no elements.
* Returns `true` if the collection has no elements.
*/
public fun <T> Iterable<T>.none(): Boolean {
for (element in this) return false
@@ -1352,7 +1353,7 @@ public inline fun <S, T: S> List<T>.reduceRight(operation: (T, S) -> S): S {
}
/**
* Returns the sum of all values produced by [transform] function from elements in the collection.
* Returns the sum of all values produced by [transform] function applied to each element in the collection.
*/
public inline fun <T> Iterable<T>.sumBy(transform: (T) -> Int): Int {
var sum: Int = 0
@@ -1363,7 +1364,7 @@ public inline fun <T> Iterable<T>.sumBy(transform: (T) -> Int): Int {
}
/**
* Returns the sum of all values produced by [transform] function from elements in the collection.
* Returns the sum of all values produced by [transform] function applied to each element in the collection.
*/
public inline fun <T> Iterable<T>.sumByDouble(transform: (T) -> Double): Double {
var sum: Double = 0.0
@@ -1436,9 +1437,9 @@ public operator fun <T> Iterable<T>.minus(sequence: Sequence<T>): List<T> {
}
/**
* Splits the original collection into pair of collections,
* where *first* collection contains elements for which [predicate] yielded `true`,
* while *second* collection contains elements for which [predicate] yielded `false`.
* Splits the original collection into pair of lists,
* where *first* list contains elements for which [predicate] yielded `true`,
* while *second* list contains elements for which [predicate] yielded `false`.
*/
public inline fun <T> Iterable<T>.partition(predicate: (T) -> Boolean): Pair<List<T>, List<T>> {
val first = ArrayList<T>()
+15 -15
View File
@@ -23,14 +23,14 @@ public fun <K, V> Map<K, V>.toList(): List<Pair<K, V>> {
}
/**
* Returns a single list of all elements yielded from results of [transform] function being invoked on each element of original collection.
* Returns a single list of all elements yielded from results of [transform] function being invoked on each entry of original map.
*/
public inline fun <K, V, R> Map<K, V>.flatMap(transform: (Map.Entry<K, V>) -> Iterable<R>): List<R> {
return flatMapTo(ArrayList<R>(), transform)
}
/**
* Appends all elements yielded from results of [transform] function being invoked on each element of original collection, to the given [destination].
* Appends all elements yielded from results of [transform] function being invoked on each entry of original map, to the given [destination].
*/
public inline fun <K, V, R, C : MutableCollection<in R>> Map<K, V>.flatMapTo(destination: C, transform: (Map.Entry<K, V>) -> Iterable<R>): C {
for (element in this) {
@@ -41,14 +41,14 @@ public inline fun <K, V, R, C : MutableCollection<in R>> Map<K, V>.flatMapTo(des
}
/**
* Returns a list containing the results of applying the given [transform] function to each element of the original collection.
* Returns a list containing the results of applying the given [transform] function to each entry of the original map.
*/
public inline fun <K, V, R> Map<K, V>.map(transform: (Map.Entry<K, V>) -> R): List<R> {
return mapTo(ArrayList<R>(size()), transform)
}
/**
* Appends transformed elements and their indices of the original collection using the given [transform] function
* Appends transformed entrys and their indices in the original map using the given [transform] function
* to the given [destination].
*/
public inline fun <K, V, R, C : MutableCollection<in R>> Map<K, V>.mapIndexedTo(destination: C, transform: (Int, Map.Entry<K, V>) -> R): C {
@@ -59,7 +59,7 @@ public inline fun <K, V, R, C : MutableCollection<in R>> Map<K, V>.mapIndexedTo(
}
/**
* Appends transformed elements of the original collection using the given [transform] function
* Appends transformed entrys of the original map using the given [transform] function
* to the given [destination].
*/
public inline fun <K, V, R, C : MutableCollection<in R>> Map<K, V>.mapTo(destination: C, transform: (Map.Entry<K, V>) -> R): C {
@@ -69,7 +69,7 @@ public inline fun <K, V, R, C : MutableCollection<in R>> Map<K, V>.mapTo(destina
}
/**
* Returns `true` if all elements match the given [predicate].
* Returns `true` if all entrys match the given [predicate].
*/
public inline fun <K, V> Map<K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -77,7 +77,7 @@ public inline fun <K, V> Map<K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean):
}
/**
* Returns `true` if collection has at least one element.
* Returns `true` if map has at least one entry.
*/
public fun <K, V> Map<K, V>.any(): Boolean {
for (element in this) return true
@@ -85,7 +85,7 @@ public fun <K, V> Map<K, V>.any(): Boolean {
}
/**
* Returns `true` if at least one element matches the given [predicate].
* Returns `true` if at least one entry matches the given [predicate].
*/
public inline fun <K, V> Map<K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -93,14 +93,14 @@ public inline fun <K, V> Map<K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean):
}
/**
* Returns the number of elements in this collection.
* Returns the number of entrys in this map.
*/
public fun <K, V> Map<K, V>.count(): Int {
return size()
}
/**
* Returns the number of elements matching the given [predicate].
* Returns the number of entrys matching the given [predicate].
*/
public inline fun <K, V> Map<K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int {
var count = 0
@@ -109,14 +109,14 @@ public inline fun <K, V> Map<K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean
}
/**
* Performs the given [operation] on each element.
* Performs the given [operation] on each entry.
*/
public inline fun <K, V> Map<K, V>.forEach(operation: (Map.Entry<K, V>) -> Unit): Unit {
for (element in this) operation(element)
}
/**
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
* Returns the first map entry yielding the largest value of the given function or `null` if there are no entries.
*/
public inline fun <K, V, R : Comparable<R>> Map<K, V>.maxBy(f: (Map.Entry<K, V>) -> R): Map.Entry<K, V>? {
val iterator = iterator()
@@ -135,7 +135,7 @@ public inline fun <K, V, R : Comparable<R>> Map<K, V>.maxBy(f: (Map.Entry<K, V>)
}
/**
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
* Returns the first map entry yielding the smallest value of the given function or `null` if there are no entries.
*/
public inline fun <K, V, R : Comparable<R>> Map<K, V>.minBy(f: (Map.Entry<K, V>) -> R): Map.Entry<K, V>? {
val iterator = iterator()
@@ -154,7 +154,7 @@ public inline fun <K, V, R : Comparable<R>> Map<K, V>.minBy(f: (Map.Entry<K, V>)
}
/**
* Returns `true` if collection has no elements.
* Returns `true` if the map has no entrys.
*/
public fun <K, V> Map<K, V>.none(): Boolean {
for (element in this) return false
@@ -162,7 +162,7 @@ public fun <K, V> Map<K, V>.none(): Boolean {
}
/**
* Returns `true` if no elements match the given [predicate].
* Returns `true` if no entrys match the given [predicate].
*/
public inline fun <K, V> Map<K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
+47 -46
View File
@@ -13,7 +13,7 @@ import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns `true` if [element] is found in the collection.
* Returns `true` if [element] is found in the sequence.
*/
public operator fun <T> Sequence<T>.contains(element: @kotlin.internal.NoInfer T): Boolean {
return indexOf(element) >= 0
@@ -30,7 +30,7 @@ public operator fun <T> Sequence<T>.contains(element: T): Boolean {
}
/**
* Returns `true` if [element] is found in the collection.
* Returns `true` if [element] is found in the sequence.
* Allows to overcome type-safety restriction of `contains` that requires to pass an element of type `T`.
*/
@Suppress("NOTHING_TO_INLINE")
@@ -39,14 +39,14 @@ public inline fun Sequence<*>.containsRaw(element: Any?): Boolean {
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection.
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this sequence.
*/
public fun <T> Sequence<T>.elementAt(index: Int): T {
return elementAtOrElse(index) { throw IndexOutOfBoundsException("Sequence doesn't contain element at index $index.") }
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection.
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this sequence.
*/
public fun <T> Sequence<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T {
if (index < 0)
@@ -62,7 +62,7 @@ public fun <T> Sequence<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection.
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this sequence.
*/
public fun <T> Sequence<T>.elementAtOrNull(index: Int): T? {
if (index < 0)
@@ -78,7 +78,7 @@ public fun <T> Sequence<T>.elementAtOrNull(index: Int): T? {
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
public inline fun <T> Sequence<T>.find(predicate: (T) -> Boolean): T? {
return firstOrNull(predicate)
@@ -93,7 +93,7 @@ public inline fun <T> Sequence<T>.findLast(predicate: (T) -> Boolean): T? {
/**
* Returns first element.
* @throws [NoSuchElementException] if the collection is empty.
* @throws [NoSuchElementException] if the sequence is empty.
*/
public fun <T> Sequence<T>.first(): T {
val iterator = iterator()
@@ -112,7 +112,7 @@ public inline fun <T> Sequence<T>.first(predicate: (T) -> Boolean): T {
}
/**
* Returns the first element, or `null` if the collection is empty.
* Returns the first element, or `null` if the sequence is empty.
*/
public fun <T> Sequence<T>.firstOrNull(): T? {
val iterator = iterator()
@@ -130,7 +130,7 @@ public inline fun <T> Sequence<T>.firstOrNull(predicate: (T) -> Boolean): T? {
}
/**
* Returns first index of [element], or -1 if the collection does not contain element.
* Returns first index of [element], or -1 if the sequence does not contain element.
*/
public fun <T> Sequence<T>.indexOf(element: @kotlin.internal.NoInfer T): Int {
var index = 0
@@ -154,7 +154,7 @@ public fun <T> Sequence<T>.indexOf(element: T): Int {
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.
* Returns index of the first element matching the given [predicate], or -1 if the sequence does not contain such element.
*/
public inline fun <T> Sequence<T>.indexOfFirst(predicate: (T) -> Boolean): Int {
var index = 0
@@ -167,7 +167,7 @@ public inline fun <T> Sequence<T>.indexOfFirst(predicate: (T) -> Boolean): Int {
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the collection does not contain such element.
* Returns index of the last element matching the given [predicate], or -1 if the sequence does not contain such element.
*/
public inline fun <T> Sequence<T>.indexOfLast(predicate: (T) -> Boolean): Int {
var lastIndex = -1
@@ -181,7 +181,7 @@ public inline fun <T> Sequence<T>.indexOfLast(predicate: (T) -> Boolean): Int {
}
/**
* Returns first index of [element], or -1 if the collection does not contain element.
* Returns first index of [element], or -1 if the sequence does not contain element.
* Allows to overcome type-safety restriction of `indexOf` that requires to pass an element of type `T`.
*/
@Suppress("NOTHING_TO_INLINE")
@@ -191,7 +191,7 @@ public inline fun Sequence<*>.indexOfRaw(element: Any?): Int {
/**
* Returns the last element.
* @throws [NoSuchElementException] if the collection is empty.
* @throws [NoSuchElementException] if the sequence is empty.
*/
public fun <T> Sequence<T>.last(): T {
val iterator = iterator()
@@ -221,7 +221,7 @@ public inline fun <T> Sequence<T>.last(predicate: (T) -> Boolean): T {
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
* Returns last index of [element], or -1 if the sequence does not contain element.
*/
public fun <T> Sequence<T>.lastIndexOf(element: @kotlin.internal.NoInfer T): Int {
var lastIndex = -1
@@ -246,7 +246,7 @@ public fun <T> Sequence<T>.lastIndexOf(element: T): Int {
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
* Returns last index of [element], or -1 if the sequence does not contain element.
* Allows to overcome type-safety restriction of `lastIndexOf` that requires to pass an element of type `T`.
*/
@Suppress("NOTHING_TO_INLINE")
@@ -255,7 +255,7 @@ public inline fun Sequence<*>.lastIndexOfRaw(element: Any?): Int {
}
/**
* Returns the last element, or `null` if the collection is empty.
* Returns the last element, or `null` if the sequence is empty.
*/
public fun <T> Sequence<T>.lastOrNull(): T? {
val iterator = iterator()
@@ -281,7 +281,7 @@ public inline fun <T> Sequence<T>.lastOrNull(predicate: (T) -> Boolean): T? {
}
/**
* Returns the single element, or throws an exception if the collection is empty or has more than one element.
* Returns the single element, or throws an exception if the sequence is empty or has more than one element.
*/
public fun <T> Sequence<T>.single(): T {
val iterator = iterator()
@@ -311,7 +311,7 @@ public inline fun <T> Sequence<T>.single(predicate: (T) -> Boolean): T {
}
/**
* Returns single element, or `null` if the collection is empty or has more than one element.
* Returns single element, or `null` if the sequence is empty or has more than one element.
*/
public fun <T> Sequence<T>.singleOrNull(): T? {
val iterator = iterator()
@@ -507,7 +507,7 @@ public inline fun <T, K> Sequence<T>.toMap(selector: (T) -> K): Map<K, T> {
}
/**
* Returns Map containing the values provided by [transform] and indexed by [selector] from the given collection.
* Returns Map containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given sequence.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public inline fun <T, K, V> Sequence<T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
@@ -519,7 +519,8 @@ public inline fun <T, K, V> Sequence<T>.toMap(selector: (T) -> K, transform: (T)
}
/**
* Returns Map containing the values from the given collection indexed by [selector].
* Returns Map containing the elements from the given sequence indexed by the key
* returned from [selector] function applied to each element.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
public inline fun <T, K> Sequence<T>.toMapBy(selector: (T) -> K): Map<K, T> {
@@ -563,14 +564,14 @@ public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.flatMapTo(dest
}
/**
* Returns a map of the elements in original collection grouped by the result of given [toKey] function.
* Returns a map of the elements in original sequence grouped by the result of given [toKey] function.
*/
public inline fun <T, K> Sequence<T>.groupBy(toKey: (T) -> K): Map<K, List<T>> {
return groupByTo(LinkedHashMap<K, MutableList<T>>(), toKey)
}
/**
* Appends elements from original collection grouped by the result of given [toKey] function to the given [map].
* Appends elements from original sequence grouped by the result of given [toKey] function to the given [map].
*/
public inline fun <T, K> Sequence<T>.groupByTo(map: MutableMap<K, MutableList<T>>, toKey: (T) -> K): Map<K, MutableList<T>> {
for (element in this) {
@@ -589,14 +590,14 @@ public fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R> {
}
/**
* Returns a sequence containing the results of applying the given [transform] function to each element and its index of the original sequence.
* Returns a sequence containing the results of applying the given [transform] function to each element and its index in the original sequence.
*/
public fun <T, R> Sequence<T>.mapIndexed(transform: (Int, T) -> R): Sequence<R> {
return TransformingIndexedSequence(this, transform)
}
/**
* Appends transformed elements and their indices of the original collection using the given [transform] function
* Appends transformed elements and their indices in the original sequence using the given [transform] function
* to the given [destination].
*/
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(destination: C, transform: (Int, T) -> R): C {
@@ -607,7 +608,7 @@ public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(d
}
/**
* Appends transformed elements of the original collection using the given [transform] function
* Appends transformed elements of the original sequence using the given [transform] function
* to the given [destination].
*/
public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapTo(destination: C, transform: (T) -> R): C {
@@ -657,7 +658,7 @@ public inline fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean {
}
/**
* Returns `true` if collection has at least one element.
* Returns `true` if sequence has at least one element.
*/
public fun <T> Sequence<T>.any(): Boolean {
for (element in this) return true
@@ -673,7 +674,7 @@ public inline fun <T> Sequence<T>.any(predicate: (T) -> Boolean): Boolean {
}
/**
* Returns the number of elements in this collection.
* Returns the number of elements in this sequence.
*/
public fun <T> Sequence<T>.count(): Int {
var count = 0
@@ -781,7 +782,7 @@ public inline fun <R : Comparable<R>, T : Any> Sequence<T>.minBy(f: (T) -> R): T
}
/**
* Returns `true` if collection has no elements.
* Returns `true` if the sequence has no elements.
*/
public fun <T> Sequence<T>.none(): Boolean {
for (element in this) return false
@@ -810,7 +811,7 @@ public inline fun <S, T: S> Sequence<T>.reduce(operation: (S, T) -> S): S {
}
/**
* Returns the sum of all values produced by [transform] function from elements in the collection.
* Returns the sum of all values produced by [transform] function applied to each element in the sequence.
*/
public inline fun <T> Sequence<T>.sumBy(transform: (T) -> Int): Int {
var sum: Int = 0
@@ -821,7 +822,7 @@ public inline fun <T> Sequence<T>.sumBy(transform: (T) -> Int): Int {
}
/**
* Returns the sum of all values produced by [transform] function from elements in the collection.
* Returns the sum of all values produced by [transform] function applied to each element in the sequence.
*/
public inline fun <T> Sequence<T>.sumByDouble(transform: (T) -> Double): Double {
var sum: Double = 0.0
@@ -900,9 +901,9 @@ public operator fun <T> Sequence<T>.minus(sequence: Sequence<T>): Sequence<T> {
}
/**
* Splits the original collection into pair of collections,
* where *first* collection contains elements for which [predicate] yielded `true`,
* while *second* collection contains elements for which [predicate] yielded `false`.
* Splits the original sequence into pair of lists,
* where *first* list contains elements for which [predicate] yielded `true`,
* while *second* list contains elements for which [predicate] yielded `false`.
*/
public inline fun <T> Sequence<T>.partition(predicate: (T) -> Boolean): Pair<List<T>, List<T>> {
val first = ArrayList<T>()
@@ -953,7 +954,7 @@ public operator fun <T> Sequence<T>.plus(sequence: Sequence<T>): Sequence<T> {
/**
* Returns a sequence of pairs built from elements of both collections with same indexes.
* Resulting sequence has length of shortest input sequences.
* Resulting sequence has length of shortest input sequence.
*/
public fun <T, R> Sequence<T>.zip(sequence: Sequence<R>): Sequence<Pair<T, R>> {
return MergingSequence(this, sequence) { t1, t2 -> t1 to t2 }
@@ -1037,7 +1038,7 @@ public fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(desti
}
/**
* Returns an average value of elements in the collection.
* Returns an average value of elements in the sequence.
*/
@kotlin.jvm.JvmName("averageOfByte")
public fun Sequence<Byte>.average(): Double {
@@ -1052,7 +1053,7 @@ public fun Sequence<Byte>.average(): Double {
}
/**
* Returns an average value of elements in the collection.
* Returns an average value of elements in the sequence.
*/
@kotlin.jvm.JvmName("averageOfDouble")
public fun Sequence<Double>.average(): Double {
@@ -1067,7 +1068,7 @@ public fun Sequence<Double>.average(): Double {
}
/**
* Returns an average value of elements in the collection.
* Returns an average value of elements in the sequence.
*/
@kotlin.jvm.JvmName("averageOfFloat")
public fun Sequence<Float>.average(): Double {
@@ -1082,7 +1083,7 @@ public fun Sequence<Float>.average(): Double {
}
/**
* Returns an average value of elements in the collection.
* Returns an average value of elements in the sequence.
*/
@kotlin.jvm.JvmName("averageOfInt")
public fun Sequence<Int>.average(): Double {
@@ -1097,7 +1098,7 @@ public fun Sequence<Int>.average(): Double {
}
/**
* Returns an average value of elements in the collection.
* Returns an average value of elements in the sequence.
*/
@kotlin.jvm.JvmName("averageOfLong")
public fun Sequence<Long>.average(): Double {
@@ -1112,7 +1113,7 @@ public fun Sequence<Long>.average(): Double {
}
/**
* Returns an average value of elements in the collection.
* Returns an average value of elements in the sequence.
*/
@kotlin.jvm.JvmName("averageOfShort")
public fun Sequence<Short>.average(): Double {
@@ -1127,7 +1128,7 @@ public fun Sequence<Short>.average(): Double {
}
/**
* Returns the sum of all elements in the collection.
* Returns the sum of all elements in the sequence.
*/
@kotlin.jvm.JvmName("sumOfByte")
public fun Sequence<Byte>.sum(): Int {
@@ -1140,7 +1141,7 @@ public fun Sequence<Byte>.sum(): Int {
}
/**
* Returns the sum of all elements in the collection.
* Returns the sum of all elements in the sequence.
*/
@kotlin.jvm.JvmName("sumOfDouble")
public fun Sequence<Double>.sum(): Double {
@@ -1153,7 +1154,7 @@ public fun Sequence<Double>.sum(): Double {
}
/**
* Returns the sum of all elements in the collection.
* Returns the sum of all elements in the sequence.
*/
@kotlin.jvm.JvmName("sumOfFloat")
public fun Sequence<Float>.sum(): Float {
@@ -1166,7 +1167,7 @@ public fun Sequence<Float>.sum(): Float {
}
/**
* Returns the sum of all elements in the collection.
* Returns the sum of all elements in the sequence.
*/
@kotlin.jvm.JvmName("sumOfInt")
public fun Sequence<Int>.sum(): Int {
@@ -1179,7 +1180,7 @@ public fun Sequence<Int>.sum(): Int {
}
/**
* Returns the sum of all elements in the collection.
* Returns the sum of all elements in the sequence.
*/
@kotlin.jvm.JvmName("sumOfLong")
public fun Sequence<Long>.sum(): Long {
@@ -1192,7 +1193,7 @@ public fun Sequence<Long>.sum(): Long {
}
/**
* Returns the sum of all elements in the collection.
* Returns the sum of all elements in the sequence.
*/
@kotlin.jvm.JvmName("sumOfShort")
public fun Sequence<Short>.sum(): Int {
+127 -125
View File
@@ -13,14 +13,14 @@ import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this char sequence.
*/
public fun CharSequence.elementAt(index: Int): Char {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.elementAt(index: Int): Char {
@@ -28,14 +28,14 @@ public fun String.elementAt(index: Int): Char {
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this char sequence.
*/
public inline fun CharSequence.elementAtOrElse(index: Int, defaultValue: (Int) -> Char): Char {
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.elementAtOrElse(index: Int, defaultValue: (Int) -> Char): Char {
@@ -43,14 +43,14 @@ public inline fun String.elementAtOrElse(index: Int, defaultValue: (Int) -> Char
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or `null` if the [index] is out of bounds of this char sequence.
*/
public fun CharSequence.elementAtOrNull(index: Int): Char? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or `null` if the [index] is out of bounds of this string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.elementAtOrNull(index: Int): Char? {
@@ -58,14 +58,14 @@ public fun String.elementAtOrNull(index: Int): Char? {
}
/**
* Returns the first character matching the given [predicate], or `null` if character was not found.
* Returns the first character matching the given [predicate], or `null` if no such character was found.
*/
public inline fun CharSequence.find(predicate: (Char) -> Boolean): Char? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
* Returns the first character matching the given [predicate], or `null` if no such character was found.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.find(predicate: (Char) -> Boolean): Char? {
@@ -80,7 +80,7 @@ public inline fun CharSequence.findLast(predicate: (Char) -> Boolean): Char? {
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
* Returns the last character matching the given [predicate], or `null` if no such character was found.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.findLast(predicate: (Char) -> Boolean): Char? {
@@ -89,7 +89,7 @@ public inline fun String.findLast(predicate: (Char) -> Boolean): Char? {
/**
* Returns first character.
* @throws [NoSuchElementException] if the CharSequence is empty.
* @throws [NoSuchElementException] if the char sequence is empty.
*/
public fun CharSequence.first(): Char {
if (isEmpty())
@@ -98,8 +98,8 @@ public fun CharSequence.first(): Char {
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the collection is empty.
* Returns first character.
* @throws [NoSuchElementException] if the string is empty.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.first(): Char {
@@ -118,8 +118,8 @@ public inline fun CharSequence.first(predicate: (Char) -> Boolean): Char {
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
* Returns the first character matching the given [predicate].
* @throws [NoSuchElementException] if no such character is found.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.first(predicate: (Char) -> Boolean): Char {
@@ -128,14 +128,14 @@ public inline fun String.first(predicate: (Char) -> Boolean): Char {
}
/**
* Returns the first character, or `null` if CharSequence is empty.
* Returns the first character, or `null` if the char sequence is empty.
*/
public fun CharSequence.firstOrNull(): Char? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the collection is empty.
* Returns the first character, or `null` if the string is empty.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.firstOrNull(): Char? {
@@ -151,7 +151,7 @@ public inline fun CharSequence.firstOrNull(predicate: (Char) -> Boolean): Char?
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
* Returns the first character matching the given [predicate], or `null` if character was not found.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.firstOrNull(predicate: (Char) -> Boolean): Char? {
@@ -160,14 +160,14 @@ public inline fun String.firstOrNull(predicate: (Char) -> Boolean): Char? {
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this char sequence.
*/
public inline fun CharSequence.getOrElse(index: Int, defaultValue: (Int) -> Char): Char {
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.getOrElse(index: Int, defaultValue: (Int) -> Char): Char {
@@ -175,14 +175,14 @@ public inline fun String.getOrElse(index: Int, defaultValue: (Int) -> Char): Cha
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or `null` if the [index] is out of bounds of this char sequence.
*/
public fun CharSequence.getOrNull(index: Int): Char? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection.
* Returns a character at the given [index] or `null` if the [index] is out of bounds of this string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.getOrNull(index: Int): Char? {
@@ -190,7 +190,7 @@ public fun String.getOrNull(index: Int): Char? {
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.
* Returns index of the first character matching the given [predicate], or -1 if the char sequence does not contain such character.
*/
public inline fun CharSequence.indexOfFirst(predicate: (Char) -> Boolean): Int {
for (index in indices) {
@@ -202,7 +202,7 @@ public inline fun CharSequence.indexOfFirst(predicate: (Char) -> Boolean): Int {
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.
* Returns index of the first character matching the given [predicate], or -1 if the string does not contain such character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.indexOfFirst(predicate: (Char) -> Boolean): Int {
@@ -215,7 +215,7 @@ public inline fun String.indexOfFirst(predicate: (Char) -> Boolean): Int {
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the collection does not contain such element.
* Returns index of the last character matching the given [predicate], or -1 if the char sequence does not contain such character.
*/
public inline fun CharSequence.indexOfLast(predicate: (Char) -> Boolean): Int {
for (index in indices.reversed()) {
@@ -227,7 +227,7 @@ public inline fun CharSequence.indexOfLast(predicate: (Char) -> Boolean): Int {
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the collection does not contain such element.
* Returns index of the last character matching the given [predicate], or -1 if the string does not contain such character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.indexOfLast(predicate: (Char) -> Boolean): Int {
@@ -240,8 +240,8 @@ public inline fun String.indexOfLast(predicate: (Char) -> Boolean): Int {
}
/**
* "Returns the last character.
* @throws [NoSuchElementException] if the string is empty.
* Returns the last character.
* @throws [NoSuchElementException] if the char sequence is empty.
*/
public fun CharSequence.last(): Char {
if (isEmpty())
@@ -250,8 +250,8 @@ public fun CharSequence.last(): Char {
}
/**
* Returns the last element.
* @throws [NoSuchElementException] if the collection is empty.
* Returns the last character.
* @throws [NoSuchElementException] if the string is empty.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.last(): Char {
@@ -261,7 +261,7 @@ public fun String.last(): Char {
}
/**
* "Returns the last character matching the given [predicate].
* Returns the last character matching the given [predicate].
* @throws [NoSuchElementException] if no such character is found.
*/
public inline fun CharSequence.last(predicate: (Char) -> Boolean): Char {
@@ -278,8 +278,8 @@ public inline fun CharSequence.last(predicate: (Char) -> Boolean): Char {
}
/**
* Returns the last element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
* Returns the last character matching the given [predicate].
* @throws [NoSuchElementException] if no such character is found.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.last(predicate: (Char) -> Boolean): Char {
@@ -296,14 +296,14 @@ public inline fun String.last(predicate: (Char) -> Boolean): Char {
}
/**
* Returns the last character, or `null` if the string is empty.
* Returns the last character, or `null` if the char sequence is empty.
*/
public fun CharSequence.lastOrNull(): Char? {
return if (isEmpty()) null else this[length() - 1]
}
/**
* Returns the last element, or `null` if the collection is empty.
* Returns the last character, or `null` if the string is empty.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.lastOrNull(): Char? {
@@ -324,7 +324,7 @@ public inline fun CharSequence.lastOrNull(predicate: (Char) -> Boolean): Char? {
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
* Returns the last character matching the given [predicate], or `null` if no such character was found.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.lastOrNull(predicate: (Char) -> Boolean): Char? {
@@ -338,7 +338,7 @@ public inline fun String.lastOrNull(predicate: (Char) -> Boolean): Char? {
}
/**
* Returns the single character, or throws an exception if the string is empty or has more than one character.
* Returns the single character, or throws an exception if the char sequence is empty or has more than one character.
*/
public fun CharSequence.single(): Char {
return when (length()) {
@@ -349,7 +349,7 @@ public fun CharSequence.single(): Char {
}
/**
* Returns the single element, or throws an exception if the collection is empty or has more than one element.
* Returns the single character, or throws an exception if the string is empty or has more than one character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.single(): Char {
@@ -378,7 +378,7 @@ public inline fun CharSequence.single(predicate: (Char) -> Boolean): Char {
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
* Returns the single character matching the given [predicate], or throws exception if there is no or more than one matching character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.single(predicate: (Char) -> Boolean): Char {
@@ -396,14 +396,14 @@ public inline fun String.single(predicate: (Char) -> Boolean): Char {
}
/**
* Returns the single character, or `null` if the string is empty or has more than one character.
* Returns single character, or `null` if the char sequence is empty or has more than one character.
*/
public fun CharSequence.singleOrNull(): Char? {
return if (length() == 1) this[0] else null
}
/**
* Returns single element, or `null` if the collection is empty or has more than one element.
* Returns single character, or `null` if the string is empty or has more than one character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.singleOrNull(): Char? {
@@ -428,7 +428,7 @@ public inline fun CharSequence.singleOrNull(predicate: (Char) -> Boolean): Char?
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
* Returns the single character matching the given [predicate], or `null` if character was not found or more than one character was found.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.singleOrNull(predicate: (Char) -> Boolean): Char? {
@@ -704,14 +704,14 @@ public fun String.reversed(): String {
}
/**
* Returns an [ArrayList] of all elements.
* Returns an [ArrayList] of all characters.
*/
public fun CharSequence.toArrayList(): ArrayList<Char> {
return toCollection(ArrayList<Char>(length()))
}
/**
* Returns an [ArrayList] of all elements.
* Returns an [ArrayList] of all characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.toArrayList(): ArrayList<Char> {
@@ -719,7 +719,7 @@ public fun String.toArrayList(): ArrayList<Char> {
}
/**
* Appends all elements to the given [collection].
* Appends all characters to the given [collection].
*/
public fun <C : MutableCollection<in Char>> CharSequence.toCollection(collection: C): C {
for (item in this) {
@@ -729,7 +729,7 @@ public fun <C : MutableCollection<in Char>> CharSequence.toCollection(collection
}
/**
* Appends all elements to the given [collection].
* Appends all characters to the given [collection].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun <C : MutableCollection<in Char>> String.toCollection(collection: C): C {
@@ -740,14 +740,14 @@ public fun <C : MutableCollection<in Char>> String.toCollection(collection: C):
}
/**
* Returns a [HashSet] of all elements.
* Returns a [HashSet] of all characters.
*/
public fun CharSequence.toHashSet(): HashSet<Char> {
return toCollection(HashSet<Char>(mapCapacity(length())))
}
/**
* Returns a [HashSet] of all elements.
* Returns a [HashSet] of all characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.toHashSet(): HashSet<Char> {
@@ -763,14 +763,14 @@ public fun String.toLinkedList(): LinkedList<Char> {
}
/**
* Returns a [List] containing all elements.
* Returns a [List] containing all characters.
*/
public fun CharSequence.toList(): List<Char> {
return this.toArrayList()
}
/**
* Returns a [List] containing all elements.
* Returns a [List] containing all characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.toList(): List<Char> {
@@ -788,8 +788,8 @@ public inline fun <K> String.toMap(selector: (Char) -> K): Map<K, Char> {
}
/**
* Returns Map containing the values provided by [transform] and indexed by [selector] from the given collection.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
* Returns Map containing the values provided by [transform] and indexed by [selector] functions applied to characters of the given char sequence.
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
*/
public inline fun <K, V> CharSequence.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
val capacity = (length()/.75f) + 1
@@ -801,8 +801,8 @@ public inline fun <K, V> CharSequence.toMap(selector: (Char) -> K, transform: (C
}
/**
* Returns Map containing the values provided by [transform] and indexed by [selector] from the given collection.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
* Returns Map containing the values provided by [transform] and indexed by [selector] functions applied to characters of the given string.
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <K, V> String.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
@@ -815,8 +815,9 @@ public inline fun <K, V> String.toMap(selector: (Char) -> K, transform: (Char) -
}
/**
* Returns Map containing the values from the given collection indexed by [selector].
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
* Returns Map containing the characters from the given char sequence indexed by the key
* returned from [selector] function applied to each character.
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
*/
public inline fun <K> CharSequence.toMapBy(selector: (Char) -> K): Map<K, Char> {
val capacity = (length()/.75f) + 1
@@ -828,8 +829,9 @@ public inline fun <K> CharSequence.toMapBy(selector: (Char) -> K): Map<K, Char>
}
/**
* Returns Map containing the values from the given collection indexed by [selector].
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
* Returns Map containing the characters from the given string indexed by the key
* returned from [selector] function applied to each character.
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <K> String.toMapBy(selector: (Char) -> K): Map<K, Char> {
@@ -842,14 +844,14 @@ public inline fun <K> String.toMapBy(selector: (Char) -> K): Map<K, Char> {
}
/**
* Returns a [Set] of all elements.
* Returns a [Set] of all characters.
*/
public fun CharSequence.toSet(): Set<Char> {
return toCollection(LinkedHashSet<Char>(mapCapacity(length())))
}
/**
* Returns a [Set] of all elements.
* Returns a [Set] of all characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.toSet(): Set<Char> {
@@ -857,14 +859,14 @@ public fun String.toSet(): Set<Char> {
}
/**
* Returns a [SortedSet] of all elements.
* Returns a [SortedSet] of all characters.
*/
public fun CharSequence.toSortedSet(): SortedSet<Char> {
return toCollection(TreeSet<Char>())
}
/**
* Returns a [SortedSet] of all elements.
* Returns a [SortedSet] of all characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.toSortedSet(): SortedSet<Char> {
@@ -872,14 +874,14 @@ public fun String.toSortedSet(): SortedSet<Char> {
}
/**
* Returns a single list of all elements yielded from results of [transform] function being invoked on each element of original collection.
* Returns a single list of all elements yielded from results of [transform] function being invoked on each character of original char sequence.
*/
public inline fun <R> CharSequence.flatMap(transform: (Char) -> Iterable<R>): List<R> {
return flatMapTo(ArrayList<R>(), transform)
}
/**
* Returns a single list of all elements yielded from results of [transform] function being invoked on each element of original collection.
* Returns a single list of all elements yielded from results of [transform] function being invoked on each character of original string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <R> String.flatMap(transform: (Char) -> Iterable<R>): List<R> {
@@ -887,7 +889,7 @@ public inline fun <R> String.flatMap(transform: (Char) -> Iterable<R>): List<R>
}
/**
* Appends all elements yielded from results of [transform] function being invoked on each element of original collection, to the given [destination].
* Appends all elements yielded from results of [transform] function being invoked on each character of original char sequence, to the given [destination].
*/
public inline fun <R, C : MutableCollection<in R>> CharSequence.flatMapTo(destination: C, transform: (Char) -> Iterable<R>): C {
for (element in this) {
@@ -898,7 +900,7 @@ public inline fun <R, C : MutableCollection<in R>> CharSequence.flatMapTo(destin
}
/**
* Appends all elements yielded from results of [transform] function being invoked on each element of original collection, to the given [destination].
* Appends all elements yielded from results of [transform] function being invoked on each character of original string, to the given [destination].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <R, C : MutableCollection<in R>> String.flatMapTo(destination: C, transform: (Char) -> Iterable<R>): C {
@@ -910,14 +912,14 @@ public inline fun <R, C : MutableCollection<in R>> String.flatMapTo(destination:
}
/**
* Returns a map of the elements in original collection grouped by the result of given [toKey] function.
* Returns a map of the characters in original char sequence grouped by the result of given [toKey] function.
*/
public inline fun <K> CharSequence.groupBy(toKey: (Char) -> K): Map<K, List<Char>> {
return groupByTo(LinkedHashMap<K, MutableList<Char>>(), toKey)
}
/**
* Returns a map of the elements in original collection grouped by the result of given [toKey] function.
* Returns a map of the characters in original string grouped by the result of given [toKey] function.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <K> String.groupBy(toKey: (Char) -> K): Map<K, List<Char>> {
@@ -925,7 +927,7 @@ public inline fun <K> String.groupBy(toKey: (Char) -> K): Map<K, List<Char>> {
}
/**
* Appends elements from original collection grouped by the result of given [toKey] function to the given [map].
* Appends characters from original char sequence grouped by the result of given [toKey] function to the given [map].
*/
public inline fun <K> CharSequence.groupByTo(map: MutableMap<K, MutableList<Char>>, toKey: (Char) -> K): Map<K, MutableList<Char>> {
for (element in this) {
@@ -937,7 +939,7 @@ public inline fun <K> CharSequence.groupByTo(map: MutableMap<K, MutableList<Char
}
/**
* Appends elements from original collection grouped by the result of given [toKey] function to the given [map].
* Appends characters from original string grouped by the result of given [toKey] function to the given [map].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <K> String.groupByTo(map: MutableMap<K, MutableList<Char>>, toKey: (Char) -> K): Map<K, MutableList<Char>> {
@@ -950,14 +952,14 @@ public inline fun <K> String.groupByTo(map: MutableMap<K, MutableList<Char>>, to
}
/**
* Returns a list containing the results of applying the given [transform] function to each element of the original collection.
* Returns a list containing the results of applying the given [transform] function to each character of the original char sequence.
*/
public inline fun <R> CharSequence.map(transform: (Char) -> R): List<R> {
return mapTo(ArrayList<R>(length()), transform)
}
/**
* Returns a list containing the results of applying the given [transform] function to each element of the original collection.
* Returns a list containing the results of applying the given [transform] function to each character of the original string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <R> String.map(transform: (Char) -> R): List<R> {
@@ -965,14 +967,14 @@ public inline fun <R> String.map(transform: (Char) -> R): List<R> {
}
/**
* Returns a list containing the results of applying the given [transform] function to each element and its index of the original collection.
* Returns a list containing the results of applying the given [transform] function to each character and its index in the original char sequence.
*/
public inline fun <R> CharSequence.mapIndexed(transform: (Int, Char) -> R): List<R> {
return mapIndexedTo(ArrayList<R>(length()), transform)
}
/**
* Returns a list containing the results of applying the given [transform] function to each element and its index of the original collection.
* Returns a list containing the results of applying the given [transform] function to each character and its index in the original string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <R> String.mapIndexed(transform: (Int, Char) -> R): List<R> {
@@ -980,7 +982,7 @@ public inline fun <R> String.mapIndexed(transform: (Int, Char) -> R): List<R> {
}
/**
* Appends transformed elements and their indices of the original collection using the given [transform] function
* Appends transformed characters and their indices in the original char sequence using the given [transform] function
* to the given [destination].
*/
public inline fun <R, C : MutableCollection<in R>> CharSequence.mapIndexedTo(destination: C, transform: (Int, Char) -> R): C {
@@ -991,7 +993,7 @@ public inline fun <R, C : MutableCollection<in R>> CharSequence.mapIndexedTo(des
}
/**
* Appends transformed elements and their indices of the original collection using the given [transform] function
* Appends transformed characters and their indices in the original string using the given [transform] function
* to the given [destination].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@@ -1003,7 +1005,7 @@ public inline fun <R, C : MutableCollection<in R>> String.mapIndexedTo(destinati
}
/**
* Appends transformed elements of the original collection using the given [transform] function
* Appends transformed characters of the original char sequence using the given [transform] function
* to the given [destination].
*/
public inline fun <R, C : MutableCollection<in R>> CharSequence.mapTo(destination: C, transform: (Char) -> R): C {
@@ -1013,7 +1015,7 @@ public inline fun <R, C : MutableCollection<in R>> CharSequence.mapTo(destinatio
}
/**
* Appends transformed elements of the original collection using the given [transform] function
* Appends transformed characters of the original string using the given [transform] function
* to the given [destination].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@@ -1024,14 +1026,14 @@ public inline fun <R, C : MutableCollection<in R>> String.mapTo(destination: C,
}
/**
* Returns a lazy [Iterable] of [IndexedValue] for each element of the original collection.
* Returns a lazy [Iterable] of [IndexedValue] for each character of the original char sequence.
*/
public fun CharSequence.withIndex(): Iterable<IndexedValue<Char>> {
return IndexingIterable { iterator() }
}
/**
* Returns a lazy [Iterable] of [IndexedValue] for each element of the original collection.
* Returns a lazy [Iterable] of [IndexedValue] for each character of the original string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.withIndex(): Iterable<IndexedValue<Char>> {
@@ -1039,7 +1041,7 @@ public fun String.withIndex(): Iterable<IndexedValue<Char>> {
}
/**
* Returns `true` if all elements match the given [predicate].
* Returns `true` if all characters match the given [predicate].
*/
public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -1047,7 +1049,7 @@ public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
}
/**
* Returns `true` if all elements match the given [predicate].
* Returns `true` if all characters match the given [predicate].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.all(predicate: (Char) -> Boolean): Boolean {
@@ -1056,7 +1058,7 @@ public inline fun String.all(predicate: (Char) -> Boolean): Boolean {
}
/**
* Returns `true` if collection has at least one element.
* Returns `true` if char sequence has at least one character.
*/
public fun CharSequence.any(): Boolean {
for (element in this) return true
@@ -1064,7 +1066,7 @@ public fun CharSequence.any(): Boolean {
}
/**
* Returns `true` if collection has at least one element.
* Returns `true` if string has at least one character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.any(): Boolean {
@@ -1073,7 +1075,7 @@ public fun String.any(): Boolean {
}
/**
* Returns `true` if at least one element matches the given [predicate].
* Returns `true` if at least one character matches the given [predicate].
*/
public inline fun CharSequence.any(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -1081,7 +1083,7 @@ public inline fun CharSequence.any(predicate: (Char) -> Boolean): Boolean {
}
/**
* Returns `true` if at least one element matches the given [predicate].
* Returns `true` if at least one character matches the given [predicate].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.any(predicate: (Char) -> Boolean): Boolean {
@@ -1090,14 +1092,14 @@ public inline fun String.any(predicate: (Char) -> Boolean): Boolean {
}
/**
* Returns the length of this string.
* Returns the length of this char sequence.
*/
public fun CharSequence.count(): Int {
return length()
}
/**
* Returns the number of elements in this collection.
* Returns the number of characters in this string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.count(): Int {
@@ -1105,7 +1107,7 @@ public fun String.count(): Int {
}
/**
* Returns the number of elements matching the given [predicate].
* Returns the number of characters matching the given [predicate].
*/
public inline fun CharSequence.count(predicate: (Char) -> Boolean): Int {
var count = 0
@@ -1114,7 +1116,7 @@ public inline fun CharSequence.count(predicate: (Char) -> Boolean): Int {
}
/**
* Returns the number of elements matching the given [predicate].
* Returns the number of characters matching the given [predicate].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.count(predicate: (Char) -> Boolean): Int {
@@ -1124,7 +1126,7 @@ public inline fun String.count(predicate: (Char) -> Boolean): Int {
}
/**
* Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
* 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 {
var accumulator = initial
@@ -1133,7 +1135,7 @@ public inline fun <R> CharSequence.fold(initial: R, operation: (R, Char) -> R):
}
/**
* Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
* Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <R> String.fold(initial: R, operation: (R, Char) -> R): R {
@@ -1143,7 +1145,7 @@ public inline fun <R> String.fold(initial: R, operation: (R, Char) -> R): R {
}
/**
* Accumulates value starting with [initial] value and applying [operation] from right to left to each element and current accumulator value.
* 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 {
var index = lastIndex
@@ -1155,7 +1157,7 @@ public inline fun <R> CharSequence.foldRight(initial: R, operation: (Char, R) ->
}
/**
* Accumulates value starting with [initial] value and applying [operation] from right to left to each element and current accumulator value.
* Accumulates value starting with [initial] value and applying [operation] from right to left to each character and current accumulator value.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <R> String.foldRight(initial: R, operation: (Char, R) -> R): R {
@@ -1168,14 +1170,14 @@ public inline fun <R> String.foldRight(initial: R, operation: (Char, R) -> R): R
}
/**
* Performs the given [operation] on each element.
* Performs the given [operation] on each character.
*/
public inline fun CharSequence.forEach(operation: (Char) -> Unit): Unit {
for (element in this) operation(element)
}
/**
* Performs the given [operation] on each element.
* Performs the given [operation] on each character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.forEach(operation: (Char) -> Unit): Unit {
@@ -1183,7 +1185,7 @@ public inline fun String.forEach(operation: (Char) -> Unit): Unit {
}
/**
* Performs the given [operation] on each element, providing sequential index with the element.
* Performs the given [operation] on each character, providing sequential index with the character.
*/
public inline fun CharSequence.forEachIndexed(operation: (Int, Char) -> Unit): Unit {
var index = 0
@@ -1191,7 +1193,7 @@ public inline fun CharSequence.forEachIndexed(operation: (Int, Char) -> Unit): U
}
/**
* Performs the given [operation] on each element, providing sequential index with the element.
* Performs the given [operation] on each character, providing sequential index with the character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.forEachIndexed(operation: (Int, Char) -> Unit): Unit {
@@ -1200,7 +1202,7 @@ public inline fun String.forEachIndexed(operation: (Int, Char) -> Unit): Unit {
}
/**
* Returns the largest element or `null` if there are no elements.
* Returns the largest character or `null` if there are no characters.
*/
public fun CharSequence.max(): Char? {
if (isEmpty()) return null
@@ -1213,7 +1215,7 @@ public fun CharSequence.max(): Char? {
}
/**
* Returns the largest element or `null` if there are no elements.
* Returns the largest character or `null` if there are no characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.max(): Char? {
@@ -1227,7 +1229,7 @@ public fun String.max(): Char? {
}
/**
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
* Returns the first character yielding the largest value of the given function or `null` if there are no characters.
*/
public inline fun <R : Comparable<R>> CharSequence.maxBy(f: (Char) -> R): Char? {
if (isEmpty()) return null
@@ -1245,7 +1247,7 @@ public inline fun <R : Comparable<R>> CharSequence.maxBy(f: (Char) -> R): Char?
}
/**
* Returns the first element yielding the largest value of the given function or `null` if there are no elements.
* Returns the first character yielding the largest value of the given function or `null` if there are no characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <R : Comparable<R>> String.maxBy(f: (Char) -> R): Char? {
@@ -1264,7 +1266,7 @@ public inline fun <R : Comparable<R>> String.maxBy(f: (Char) -> R): Char? {
}
/**
* Returns the smallest element or `null` if there are no elements.
* Returns the smallest character or `null` if there are no characters.
*/
public fun CharSequence.min(): Char? {
if (isEmpty()) return null
@@ -1277,7 +1279,7 @@ public fun CharSequence.min(): Char? {
}
/**
* Returns the smallest element or `null` if there are no elements.
* Returns the smallest character or `null` if there are no characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.min(): Char? {
@@ -1291,7 +1293,7 @@ public fun String.min(): Char? {
}
/**
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
* Returns the first character yielding the smallest value of the given function or `null` if there are no characters.
*/
public inline fun <R : Comparable<R>> CharSequence.minBy(f: (Char) -> R): Char? {
if (isEmpty()) return null
@@ -1309,7 +1311,7 @@ public inline fun <R : Comparable<R>> CharSequence.minBy(f: (Char) -> R): Char?
}
/**
* Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
* Returns the first character yielding the smallest value of the given function or `null` if there are no characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <R : Comparable<R>> String.minBy(f: (Char) -> R): Char? {
@@ -1328,7 +1330,7 @@ public inline fun <R : Comparable<R>> String.minBy(f: (Char) -> R): Char? {
}
/**
* Returns `true` if collection has no elements.
* Returns `true` if the char sequence has no characters.
*/
public fun CharSequence.none(): Boolean {
for (element in this) return false
@@ -1336,7 +1338,7 @@ public fun CharSequence.none(): Boolean {
}
/**
* Returns `true` if collection has no elements.
* Returns `true` if the string has no characters.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.none(): Boolean {
@@ -1345,7 +1347,7 @@ public fun String.none(): Boolean {
}
/**
* Returns `true` if no elements match the given [predicate].
* Returns `true` if no characters match the given [predicate].
*/
public inline fun CharSequence.none(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -1353,7 +1355,7 @@ public inline fun CharSequence.none(predicate: (Char) -> Boolean): Boolean {
}
/**
* Returns `true` if no elements match the given [predicate].
* Returns `true` if no characters match the given [predicate].
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.none(predicate: (Char) -> Boolean): Boolean {
@@ -1362,7 +1364,7 @@ public inline fun String.none(predicate: (Char) -> Boolean): Boolean {
}
/**
* Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element.
* 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 {
val iterator = this.iterator()
@@ -1375,7 +1377,7 @@ public inline fun CharSequence.reduce(operation: (Char, Char) -> Char): Char {
}
/**
* Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element.
* Accumulates value starting with the first character and applying [operation] from left to right to current accumulator value and each character.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.reduce(operation: (Char, Char) -> Char): Char {
@@ -1389,7 +1391,7 @@ public inline fun String.reduce(operation: (Char, Char) -> Char): Char {
}
/**
* Accumulates value starting with last element and applying [operation] from right to left to each element and current accumulator value.
* 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 {
var index = lastIndex
@@ -1402,7 +1404,7 @@ public inline fun CharSequence.reduceRight(operation: (Char, Char) -> Char): Cha
}
/**
* Accumulates value starting with last element and applying [operation] from right to left to each element and current accumulator value.
* Accumulates value starting with last character and applying [operation] from right to left to each character and current accumulator value.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.reduceRight(operation: (Char, Char) -> Char): Char {
@@ -1416,7 +1418,7 @@ public inline fun String.reduceRight(operation: (Char, Char) -> Char): Char {
}
/**
* Returns the sum of all values produced by [transform] function from characters in the string.
* Returns the sum of all values produced by [transform] function applied to each character in the char sequence.
*/
public inline fun CharSequence.sumBy(transform: (Char) -> Int): Int {
var sum: Int = 0
@@ -1427,7 +1429,7 @@ public inline fun CharSequence.sumBy(transform: (Char) -> Int): Int {
}
/**
* Returns the sum of all values produced by [transform] function from elements in the collection.
* Returns the sum of all values produced by [transform] function applied to each character in the string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.sumBy(transform: (Char) -> Int): Int {
@@ -1439,7 +1441,7 @@ public inline fun String.sumBy(transform: (Char) -> Int): Int {
}
/**
* Returns the sum of all values produced by [transform] function from characters in the string.
* Returns the sum of all values produced by [transform] function applied to each character in the char sequence.
*/
public inline fun CharSequence.sumByDouble(transform: (Char) -> Double): Double {
var sum: Double = 0.0
@@ -1450,7 +1452,7 @@ public inline fun CharSequence.sumByDouble(transform: (Char) -> Double): Double
}
/**
* Returns the sum of all values produced by [transform] function from elements in the collection.
* Returns the sum of all values produced by [transform] function applied to each character in the string.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.sumByDouble(transform: (Char) -> Double): Double {
@@ -1462,7 +1464,7 @@ public inline fun String.sumByDouble(transform: (Char) -> Double): Double {
}
/**
* Splits the original string into pair of strings,
* Splits the original char sequence into pair of strings,
* where *first* string contains characters for which [predicate] yielded `true`,
* while *second* string contains characters for which [predicate] yielded `false`.
*/
@@ -1480,9 +1482,9 @@ public inline fun CharSequence.partition(predicate: (Char) -> Boolean): Pair<Str
}
/**
* Splits the original collection into pair of collections,
* where *first* collection contains elements for which [predicate] yielded `true`,
* while *second* collection contains elements for which [predicate] yielded `false`.
* Splits the original string into pair of lists,
* where *first* list contains elements for which [predicate] yielded `true`,
* while *second* list contains elements for which [predicate] yielded `false`.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun String.partition(predicate: (Char) -> Boolean): Pair<String, String> {
@@ -1499,14 +1501,14 @@ public inline fun String.partition(predicate: (Char) -> Boolean): Pair<String, S
}
/**
* Returns a list of pairs built from characters of both strings with same indexes. List has length of shortest collection.
* Returns a list of pairs built from characters of both char sequences with same indexes. List has length of shortest char sequence.
*/
public fun CharSequence.zip(other: String): List<Pair<Char, Char>> {
return zip(other) { c1, c2 -> c1 to c2 }
}
/**
* Returns a list of pairs built from characters of both strings with same indexes. List has length of shortest collection.
* Returns a list of pairs built from characters of both char sequences with same indexes. List has length of shortest char sequence.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public fun String.zip(other: String): List<Pair<Char, Char>> {
@@ -1514,7 +1516,7 @@ public fun String.zip(other: String): List<Pair<Char, Char>> {
}
/**
* Returns a list of values built from characters of both strings with same indexes using provided [transform]. List has length of shortest string.
* 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: String, transform: (Char, Char) -> V): List<V> {
val length = Math.min(this.length(), other.length())
@@ -1526,7 +1528,7 @@ public inline fun <V> CharSequence.zip(other: String, transform: (Char, Char) ->
}
/**
* Returns a list of values built from characters of both strings with same indexes using provided [transform]. List has length of shortest string.
* 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.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public inline fun <V> String.zip(other: String, transform: (Char, Char) -> V): List<V> {
+10 -10
View File
@@ -132,17 +132,17 @@ public fun CharSequence.padEnd(length: Int, padChar: Char = ' '): String {
}
/**
* Returns `true` if this nullable string is either `null` or empty.
* Returns `true` if this nullable char sequence is either `null` or empty.
*/
public fun CharSequence?.isNullOrEmpty(): Boolean = this == null || this.length() == 0
/**
* Returns `true` if this string is empty (contains no characters).
* Returns `true` if this char sequence is empty (contains no characters).
*/
public fun CharSequence.isEmpty(): Boolean = length() == 0
/**
* Returns `true` if this string is not empty.
* Returns `true` if this char sequence is not empty.
*/
public fun CharSequence.isNotEmpty(): Boolean = length() > 0
@@ -151,12 +151,12 @@ public fun CharSequence.isNotEmpty(): Boolean = length() > 0
/**
* Returns `true` if this string is not empty and contains some characters except of whitespace characters.
* Returns `true` if this char sequence is not empty and contains some characters except of whitespace characters.
*/
public fun CharSequence.isNotBlank(): Boolean = !isBlank()
/**
* Returns `true` if this nullable string is either `null` or empty or consists solely of whitespace characters.
* Returns `true` if this nullable char sequence is either `null` or empty or consists solely of whitespace characters.
*/
public fun CharSequence?.isNullOrBlank(): Boolean = this == null || this.isBlank()
@@ -175,13 +175,13 @@ public operator fun CharSequence.iterator(): CharIterator = object : CharIterato
public fun String?.orEmpty(): String = this ?: ""
/**
* Returns the range of valid character indices for this string.
* Returns the range of valid character indices for this char sequence.
*/
public val CharSequence.indices: IntRange
get() = 0..length() - 1
/**
* Returns the index of the last character in the String or -1 if the String is empty.
* Returns the index of the last character in the char sequence or -1 if it is empty.
*/
public val CharSequence.lastIndex: Int
get() = this.length() - 1
@@ -529,7 +529,7 @@ public fun CharSequence.replaceFirst(regex: Regex, replacement: String): String
/**
* Returns `true` if this string matches the given regular expression.
* Returns `true` if this char sequence matches the given regular expression.
*/
public fun CharSequence.matches(regex: Regex): Boolean = regex.matches(this)
@@ -551,13 +551,13 @@ internal fun CharSequence.regionMatchesImpl(thisOffset: Int, other: CharSequence
}
/**
* Returns `true` if this string starts with the specified character.
* Returns `true` if this char sequence starts with the specified character.
*/
public fun CharSequence.startsWith(char: Char, ignoreCase: Boolean = false): Boolean =
this.length() > 0 && this[0].equals(char, ignoreCase)
/**
* Returns `true` if this string ends with the specified character.
* Returns `true` if this char sequence ends with the specified character.
*/
public fun CharSequence.endsWith(char: Char, ignoreCase: Boolean = false): Boolean =
this.length() > 0 && this[lastIndex].equals(char, ignoreCase)
@@ -1,13 +1,15 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
fun aggregates(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
templates add f("all(predicate: (T) -> Boolean)") {
inline(true)
doc { "Returns `true` if all elements match the given [predicate]." }
doc { f -> "Returns `true` if all ${f.element}s match the given [predicate]." }
returns("Boolean")
body {
"""
@@ -22,7 +24,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("none(predicate: (T) -> Boolean)") {
inline(true)
doc { "Returns `true` if no elements match the given [predicate]." }
doc { f -> "Returns `true` if no ${f.element}s match the given [predicate]." }
returns("Boolean")
body {
"""
@@ -35,7 +37,7 @@ fun aggregates(): List<GenericFunction> {
}
templates add f("none()") {
doc { "Returns `true` if collection has no elements." }
doc { f -> "Returns `true` if the ${f.collection} has no ${f.element}s." }
returns("Boolean")
body {
"""
@@ -50,7 +52,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("any(predicate: (T) -> Boolean)") {
inline(true)
doc { "Returns `true` if at least one element matches the given [predicate]." }
doc { f -> "Returns `true` if at least one ${f.element} matches the given [predicate]." }
returns("Boolean")
body {
"""
@@ -63,7 +65,7 @@ fun aggregates(): List<GenericFunction> {
}
templates add f("any()") {
doc { "Returns `true` if collection has at least one element." }
doc { f -> "Returns `true` if ${f.collection} has at least one ${f.element}." }
returns("Boolean")
body {
"""
@@ -78,7 +80,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("count(predicate: (T) -> Boolean)") {
inline(true)
doc { "Returns the number of elements matching the given [predicate]." }
doc { f -> "Returns the number of ${f.element}s matching the given [predicate]." }
returns("Int")
body {
"""
@@ -92,7 +94,7 @@ fun aggregates(): List<GenericFunction> {
}
templates add f("count()") {
doc { "Returns the number of elements in this collection." }
doc { f -> "Returns the number of ${f.element}s in this ${f.collection}." }
returns("Int")
body {
"""
@@ -102,7 +104,7 @@ fun aggregates(): List<GenericFunction> {
"""
}
deprecate(Strings) { forBinaryCompatibility }
doc(CharSequences) { "Returns the length of this string."}
doc(CharSequences) { "Returns the length of this char sequence."}
body(CharSequences, Strings) {
"return length()"
}
@@ -115,8 +117,7 @@ fun aggregates(): List<GenericFunction> {
inline(true)
include(CharSequences, Strings)
deprecate(Strings) { forBinaryCompatibility }
doc { "Returns the sum of all values produced by [transform] function from elements in the collection." }
doc(CharSequences) { "Returns the sum of all values produced by [transform] function from characters in the string." }
doc { f -> "Returns the sum of all values produced by [transform] function applied to each ${f.element} in the ${f.collection}." }
returns("Int")
body {
"""
@@ -133,8 +134,7 @@ fun aggregates(): List<GenericFunction> {
inline(true)
include(CharSequences, Strings)
deprecate(Strings) { forBinaryCompatibility }
doc { "Returns the sum of all values produced by [transform] function from elements in the collection." }
doc(CharSequences) { "Returns the sum of all values produced by [transform] function from characters in the string." }
doc { f -> "Returns the sum of all values produced by [transform] function applied to each ${f.element} in the ${f.collection}." }
returns("Double")
body {
"""
@@ -148,7 +148,7 @@ fun aggregates(): List<GenericFunction> {
}
templates add f("min()") {
doc { "Returns the smallest element or `null` if there are no elements." }
doc { f -> "Returns the smallest ${f.element} or `null` if there are no ${f.element}s." }
returns("T?")
exclude(PrimitiveType.Boolean)
typeParam("T : Comparable<T>")
@@ -182,7 +182,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("minBy(f: (T) -> R)") {
inline(true)
doc { "Returns the first element yielding the smallest value of the given function or `null` if there are no elements." }
doc { f -> "Returns the first ${f.element} yielding the smallest value of the given function or `null` if there are no ${f.element}s." }
typeParam("R : Comparable<R>")
typeParam("T : Any")
returns("T?")
@@ -228,7 +228,7 @@ fun aggregates(): List<GenericFunction> {
inline(true)
only(Maps)
doc { "Returns the first element yielding the smallest value of the given function or `null` if there are no elements." }
doc { "Returns the first map entry yielding the smallest value of the given function or `null` if there are no entries." }
typeParam("R : Comparable<R>")
returns("T?")
body {
@@ -252,7 +252,7 @@ fun aggregates(): List<GenericFunction> {
}
templates add f("max()") {
doc { "Returns the largest element or `null` if there are no elements." }
doc { f -> "Returns the largest ${f.element} or `null` if there are no ${f.element}s." }
returns("T?")
exclude(PrimitiveType.Boolean)
typeParam("T : Comparable<T>")
@@ -288,7 +288,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("maxBy(f: (T) -> R)") {
inline(true)
doc { "Returns the first element yielding the largest value of the given function or `null` if there are no elements." }
doc { f -> "Returns the first ${f.element} yielding the largest value of the given function or `null` if there are no ${f.element}s." }
typeParam("R : Comparable<R>")
typeParam("T : Any")
returns("T?")
@@ -334,7 +334,7 @@ fun aggregates(): List<GenericFunction> {
inline(true)
only(Maps)
doc { "Returns the first element yielding the largest value of the given function or `null` if there are no elements." }
doc { "Returns the first map entry yielding the largest value of the given function or `null` if there are no entries." }
typeParam("R : Comparable<R>")
returns("T?")
body {
@@ -362,7 +362,7 @@ fun aggregates(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element." }
doc { f -> "Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each ${f.element}." }
typeParam("R")
returns("R")
body {
@@ -379,7 +379,7 @@ fun aggregates(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
doc { "Accumulates value starting with [initial] value and applying [operation] from right to left to each element and current accumulator value." }
doc { f -> "Accumulates value starting with [initial] value and applying [operation] from right to left to each ${f.element} and current accumulator value." }
typeParam("R")
returns("R")
body {
@@ -401,7 +401,7 @@ fun aggregates(): List<GenericFunction> {
include(CharSequences, Strings)
exclude(ArraysOfObjects, Iterables, Sequences)
doc { "Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element." }
doc { f -> "Accumulates value starting with the first ${f.element} and applying [operation] from left to right to current accumulator value and each ${f.element}." }
returns("T")
body {
"""
@@ -421,7 +421,7 @@ fun aggregates(): List<GenericFunction> {
inline(true)
only(ArraysOfObjects, Iterables, Sequences)
doc { "Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element." }
doc { f -> "Accumulates value starting with the first ${f.element} and applying [operation] from left to right to current accumulator value and each ${f.element}." }
typeParam("S")
typeParam("T: S")
returns("S")
@@ -444,7 +444,7 @@ fun aggregates(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings, ArraysOfPrimitives)
doc { "Accumulates value starting with last element and applying [operation] from right to left to each element and current accumulator value." }
doc { f -> "Accumulates value starting with last ${f.element} and applying [operation] from right to left to each ${f.element} and current accumulator value." }
returns("T")
body {
"""
@@ -465,7 +465,7 @@ fun aggregates(): List<GenericFunction> {
inline(true)
only(Lists, ArraysOfObjects)
doc { "Accumulates value starting with last element and applying [operation] from right to left to each element and current accumulator value." }
doc { f -> "Accumulates value starting with last ${f.element} and applying [operation] from right to left to each ${f.element} and current accumulator value." }
typeParam("S")
typeParam("T: S")
returns("S")
@@ -487,7 +487,7 @@ fun aggregates(): List<GenericFunction> {
templates add f("forEach(operation: (T) -> Unit)") {
inline(true)
doc { "Performs the given [operation] on each element." }
doc { f -> "Performs the given [operation] on each ${f.element}." }
returns("Unit")
body {
"""
@@ -502,7 +502,7 @@ fun aggregates(): List<GenericFunction> {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Performs the given [operation] on each element, providing sequential index with the element." }
doc { f -> "Performs the given [operation] on each ${f.element}, providing sequential index with the ${f.element}." }
returns("Unit")
body {
"""
@@ -0,0 +1,32 @@
package templates
import templates.Family.*
object DocExtensions {
val Family.element: String
get() = when (this) {
Strings, CharSequences -> "character"
Maps -> "entry"
else -> "element"
}
val Family.collection: String
get() = when (this) {
CharSequences -> "char sequence"
Strings -> "string"
Sequences -> "sequence"
Maps -> "map"
ArraysOfObjects, ArraysOfPrimitives, InvariantArraysOfObjects -> "array"
else -> "collection"
}
val Family.mapResult: String
get() = when (this) {
Sequences -> "sequence"
else -> "list"
}
fun String.prefixWithArticle() = (if ("aeiou".any { this.startsWith(it, ignoreCase = true) }) "an " else "a ").concat(this)
}
@@ -1,15 +1,20 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
import templates.DocExtensions.prefixWithArticle
fun elements(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
templates add f("contains(element: T)") {
operator(true)
only(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns `true` if [element] is found in the collection." }
doc { f -> "Returns `true` if [element] is found in the ${f.collection}." }
customSignature(Iterables, ArraysOfObjects, Sequences) { "contains(element: @kotlin.internal.NoInfer T)" }
returns("Boolean")
body(Iterables) {
@@ -41,9 +46,9 @@ fun elements(): List<GenericFunction> {
templates add f("containsRaw(element: Any?)") {
only(Iterables, Sequences, ArraysOfObjects)
doc {
doc { f ->
"""
Returns `true` if [element] is found in the collection.
Returns `true` if [element] is found in the ${f.collection}.
Allows to overcome type-safety restriction of `contains` that requires to pass an element of type `T`.
"""
}
@@ -56,7 +61,7 @@ fun elements(): List<GenericFunction> {
templates add f("indexOf(element: T)") {
only(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns first index of [element], or -1 if the collection does not contain element." }
doc { f -> "Returns first index of [element], or -1 if the ${f.collection} does not contain element." }
customSignature(Iterables, ArraysOfObjects, Sequences) { "indexOf(element: @kotlin.internal.NoInfer T)" }
returns("Int")
body { f ->
@@ -116,9 +121,9 @@ fun elements(): List<GenericFunction> {
templates add f("indexOfRaw(element: Any?)") {
only(Iterables, Sequences, ArraysOfObjects, Lists)
doc {
doc { f ->
"""
Returns first index of [element], or -1 if the collection does not contain element.
Returns first index of [element], or -1 if the ${f.collection} does not contain element.
Allows to overcome type-safety restriction of `indexOf` that requires to pass an element of type `T`.
"""
}
@@ -132,7 +137,7 @@ fun elements(): List<GenericFunction> {
templates add f("lastIndexOf(element: T)") {
only(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns last index of [element], or -1 if the collection does not contain element." }
doc { f -> "Returns last index of [element], or -1 if the ${f.collection} does not contain element." }
customSignature(Iterables, ArraysOfObjects, Sequences) { "lastIndexOf(element: @kotlin.internal.NoInfer T)" }
returns("Int")
body { f ->
@@ -193,9 +198,9 @@ fun elements(): List<GenericFunction> {
templates add f("lastIndexOfRaw(element: Any?)") {
only(Iterables, Sequences, ArraysOfObjects, Lists)
doc {
doc { f ->
"""
Returns last index of [element], or -1 if the collection does not contain element.
Returns last index of [element], or -1 if the ${f.collection} does not contain element.
Allows to overcome type-safety restriction of `lastIndexOf` that requires to pass an element of type `T`.
"""
}
@@ -210,7 +215,7 @@ fun elements(): List<GenericFunction> {
templates add f("indexOfFirst(predicate: (T) -> Boolean)") {
inline(true)
doc { "Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element." }
doc { f -> "Returns index of the first ${f.element} matching the given [predicate], or -1 if the ${f.collection} does not contain such ${f.element}." }
returns("Int")
body {
"""
@@ -240,7 +245,7 @@ fun elements(): List<GenericFunction> {
templates add f("indexOfLast(predicate: (T) -> Boolean)") {
inline(true)
doc { "Returns index of the last element matching the given [predicate], or -1 if the collection does not contain such element." }
doc { f -> "Returns index of the last ${f.element} matching the given [predicate], or -1 if the ${f.collection} does not contain such ${f.element}." }
returns("Int")
body {
"""
@@ -270,7 +275,7 @@ fun elements(): List<GenericFunction> {
templates add f("elementAt(index: Int)") {
val index = '$' + "index"
doc { "Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection." }
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this ${f.collection}." }
returns("T")
body {
"""
@@ -294,7 +299,7 @@ fun elements(): List<GenericFunction> {
}
templates add f("elementAtOrElse(index: Int, defaultValue: (Int) -> T)") {
doc { "Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection." }
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this ${f.collection}." }
returns("T")
body {
"""
@@ -336,7 +341,7 @@ fun elements(): List<GenericFunction> {
}
templates add f("getOrElse(index: Int, defaultValue: (Int) -> T)") {
doc { "Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this collection." }
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this ${f.collection}." }
returns("T")
inline(true)
deprecate(Strings) { forBinaryCompatibility }
@@ -350,7 +355,7 @@ fun elements(): List<GenericFunction> {
templates add f("elementAtOrNull(index: Int)") {
doc { "Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection." }
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." }
returns("T?")
body {
"""
@@ -391,7 +396,7 @@ fun elements(): List<GenericFunction> {
}
templates add f("getOrNull(index: Int)") {
doc { "Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection." }
doc { f -> "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." }
returns("T?")
deprecate(Strings) { forBinaryCompatibility }
only(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
@@ -404,11 +409,8 @@ fun elements(): List<GenericFunction> {
templates add f("first()") {
doc { """Returns first element.
@throws [NoSuchElementException] if the collection is empty.
""" }
doc(CharSequences) { """Returns first character.
@throws [NoSuchElementException] if the CharSequence is empty.
doc { f -> """Returns first ${f.element}.
@throws [NoSuchElementException] if the ${f.collection} is empty.
""" }
returns("T")
body {
@@ -447,8 +449,7 @@ fun elements(): List<GenericFunction> {
}
}
templates add f("firstOrNull()") {
doc { "Returns the first element, or `null` if the collection is empty." }
doc(CharSequences) { "Returns the first character, or `null` if CharSequence is empty." }
doc { f -> "Returns the first ${f.element}, or `null` if the ${f.collection} is empty." }
returns("T?")
body {
"""
@@ -489,10 +490,8 @@ fun elements(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { """Returns the first element matching the given [predicate].
@throws [NoSuchElementException] if no such element is found.""" }
doc(CharSequences) { """Returns the first character matching the given [predicate].
@throws [NoSuchElementException] if no such character is found.""" }
doc { f -> """Returns the first ${f.element} matching the given [predicate].
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
returns("T")
body {
"""
@@ -507,8 +506,7 @@ fun elements(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns the first element matching the given [predicate], or `null` if element was not found." }
doc(CharSequences) { "Returns the first character matching the given [predicate], or `null` if character was not found." }
doc { f -> "Returns the first ${f.element} matching the given [predicate], or `null` if ${f.element} was not found." }
returns("T?")
body {
"""
@@ -522,17 +520,14 @@ fun elements(): List<GenericFunction> {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns the first element matching the given [predicate], or `null` if element was not found." }
doc(CharSequences) { "Returns the first character matching the given [predicate], or `null` if character was not found." }
doc { f -> "Returns the first ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
returns("T?")
body { "return firstOrNull(predicate)"}
}
templates add f("last()") {
doc { """Returns the last element.
@throws [NoSuchElementException] if the collection is empty.""" }
doc(CharSequences) { """"Returns the last character.
@throws [NoSuchElementException] if the string is empty.""" }
doc { f -> """Returns the last ${f.element}.
@throws [NoSuchElementException] if the ${f.collection} is empty.""" }
returns("T")
body {
"""
@@ -577,8 +572,7 @@ fun elements(): List<GenericFunction> {
}
templates add f("lastOrNull()") {
doc { "Returns the last element, or `null` if the collection is empty." }
doc(CharSequences) { "Returns the last character, or `null` if the string is empty." }
doc { f -> "Returns the last ${f.element}, or `null` if the ${f.collection} is empty." }
returns("T?")
body {
"""
@@ -625,10 +619,8 @@ fun elements(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { """Returns the last element matching the given [predicate].
@throws [NoSuchElementException] if no such element is found.""" }
doc(CharSequences) { """"Returns the last character matching the given [predicate].
@throws [NoSuchElementException] if no such character is found.""" }
doc { f -> """Returns the last ${f.element} matching the given [predicate].
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
returns("T")
body { f ->
(if (f == Iterables)
@@ -666,8 +658,7 @@ fun elements(): List<GenericFunction> {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns the last element matching the given [predicate], or `null` if no such element was found." }
doc(CharSequences) { "Returns the last character matching the given [predicate], or `null` if no such character was found." }
doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
returns("T?")
body { f ->
(if (f == Iterables)
@@ -702,15 +693,13 @@ fun elements(): List<GenericFunction> {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(Lists, CharSequences, Strings)
doc { "Returns the last element matching the given [predicate], or `null` if no such element was found." }
doc(CharSequences) { "Returns the last character matching the given [predicate], or `null` if no such character was found." }
doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
returns("T?")
body { "return lastOrNull(predicate)"}
}
templates add f("single()") {
doc { "Returns the single element, or throws an exception if the collection is empty or has more than one element." }
doc(CharSequences) { "Returns the single character, or throws an exception if the string is empty or has more than one character." }
doc { f -> "Returns the single ${f.element}, or throws an exception if the ${f.collection} is empty or has more than one ${f.element}." }
returns("T")
body {
"""
@@ -765,8 +754,7 @@ fun elements(): List<GenericFunction> {
}
templates add f("singleOrNull()") {
doc { "Returns single element, or `null` if the collection is empty or has more than one element." }
doc(CharSequences) { "Returns the single character, or `null` if the string is empty or has more than one character." }
doc { f -> "Returns single ${f.element}, or `null` if the ${f.collection} is empty or has more than one ${f.element}." }
returns("T?")
body {
"""
@@ -812,8 +800,7 @@ fun elements(): List<GenericFunction> {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element." }
doc(CharSequences) { "Returns the single character matching the given [predicate], or throws exception if there is no or more than one matching character." }
doc { f -> "Returns the single ${f.element} matching the given [predicate], or throws exception if there is no or more than one matching ${f.element}." }
returns("T")
body {
"""
@@ -836,8 +823,7 @@ fun elements(): List<GenericFunction> {
inline(true)
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found." }
doc(CharSequences) { "Returns the single character matching the given [predicate], or `null` if character was not found or more than one character was found." }
doc { f -> "Returns the single ${f.element} matching the given [predicate], or `null` if ${f.element} was not found or more than one ${f.element} was found." }
returns("T?")
body {
"""
@@ -1,6 +1,7 @@
package templates
import templates.Family.*
import templates.DocExtensions.collection
fun generators(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -395,11 +396,11 @@ fun generators(): List<GenericFunction> {
templates add f("partition(predicate: (T) -> Boolean)") {
inline(true)
doc {
doc { f ->
"""
Splits the original collection into pair of collections,
where *first* collection contains elements for which [predicate] yielded `true`,
while *second* collection contains elements for which [predicate] yielded `false`.
Splits the original ${f.collection} into pair of lists,
where *first* list contains elements for which [predicate] yielded `true`,
while *second* list contains elements for which [predicate] yielded `false`.
"""
}
// TODO: Sequence variant
@@ -422,7 +423,7 @@ fun generators(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
doc(CharSequences) {
"""
Splits the original string into pair of strings,
Splits the original char sequence into pair of strings,
where *first* string contains characters for which [predicate] yielded `true`,
while *second* string contains characters for which [predicate] yielded `false`.
"""
@@ -560,7 +561,7 @@ fun generators(): List<GenericFunction> {
only(CharSequences, Strings)
doc {
"""
Returns a list of values built from characters of both strings with same indexes using provided [transform]. List has length of shortest string.
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.
"""
}
typeParam("V")
@@ -601,7 +602,7 @@ fun generators(): List<GenericFunction> {
only(CharSequences, Strings)
doc {
"""
Returns a list of pairs built from characters of both strings with same indexes. List has length of shortest collection.
Returns a list of pairs built from characters of both char sequences with same indexes. List has length of shortest char sequence.
"""
}
returns("List<Pair<Char, Char>>")
@@ -648,7 +649,7 @@ fun generators(): List<GenericFunction> {
doc {
"""
Returns a sequence of pairs built from elements of both collections with same indexes.
Resulting sequence has length of shortest input sequences.
Resulting sequence has length of shortest input sequence.
"""
}
typeParam("R")
@@ -1,6 +1,9 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
import templates.DocExtensions.mapResult
fun mapping(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -8,7 +11,7 @@ fun mapping(): List<GenericFunction> {
templates add f("withIndex()") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns a lazy [Iterable] of [IndexedValue] for each element of the original collection." }
doc { f -> "Returns a ${if (f == Sequences) f.mapResult else "lazy [Iterable]"} of [IndexedValue] for each ${f.element} of the original ${f.collection}." }
returns("Iterable<IndexedValue<T>>")
body {
"""
@@ -17,7 +20,6 @@ fun mapping(): List<GenericFunction> {
}
returns(Sequences) { "Sequence<IndexedValue<T>>" }
doc(Sequences) { "Returns a sequence of [IndexedValue] for each element of the original sequence." }
body(Sequences) {
"""
return IndexingSequence(this)
@@ -28,7 +30,7 @@ fun mapping(): List<GenericFunction> {
templates add f("mapIndexed(transform: (Int, T) -> R)") {
inline(true)
doc { "Returns a list containing the results of applying the given [transform] function to each element and its index of the original collection." }
doc { f -> "Returns a ${f.mapResult} containing the results of applying the given [transform] function to each ${f.element} and its index in the original ${f.collection}." }
typeParam("R")
returns("List<R>")
body {
@@ -43,7 +45,6 @@ fun mapping(): List<GenericFunction> {
}
inline(false, Sequences)
returns(Sequences) { "Sequence<R>" }
doc(Sequences) { "Returns a sequence containing the results of applying the given [transform] function to each element and its index of the original sequence." }
body(Sequences) {
"return TransformingIndexedSequence(this, transform)"
}
@@ -52,7 +53,7 @@ fun mapping(): List<GenericFunction> {
templates add f("map(transform: (T) -> R)") {
inline(true)
doc { "Returns a list containing the results of applying the given [transform] function to each element of the original collection." }
doc { f -> "Returns a ${f.mapResult} containing the results of applying the given [transform] function to each ${f.element} of the original ${f.collection}." }
typeParam("R")
returns("List<R>")
body {
@@ -68,7 +69,6 @@ fun mapping(): List<GenericFunction> {
inline(false, Sequences)
returns(Sequences) { "Sequence<R>" }
doc(Sequences) { "Returns a sequence containing the results of applying the given [transform] function to each element of the original sequence." }
body(Sequences) {
"return TransformingSequence(this, transform)"
}
@@ -79,7 +79,7 @@ fun mapping(): List<GenericFunction> {
templates add f("mapNotNull(transform: (T) -> R)") {
inline(true)
exclude(Strings, ArraysOfPrimitives)
doc { "Returns a list containing the results of applying the given [transform] function to each non-null element of the original collection." }
doc { f -> "Returns a ${f.mapResult} containing the results of applying the given [transform] function to each non-null ${f.element} of the original ${f.collection}." }
deprecate(Deprecation("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().map {} instead.", replaceWith = "filterNotNull().map(transform)"))
typeParam("T : Any")
typeParam("R")
@@ -91,7 +91,6 @@ fun mapping(): List<GenericFunction> {
"""
}
doc(Sequences) { "Returns a sequence containing the results of applying the given [transform] function to each non-null element of the original sequence." }
returns(Sequences) { "Sequence<R>" }
inline(false, Sequences)
body(Sequences) {
@@ -105,9 +104,9 @@ fun mapping(): List<GenericFunction> {
templates add f("mapTo(destination: C, transform: (T) -> R)") {
inline(true)
doc {
doc { f ->
"""
Appends transformed elements of the original collection using the given [transform] function
Appends transformed ${f.element}s of the original ${f.collection} using the given [transform] function
to the given [destination].
"""
}
@@ -129,9 +128,9 @@ fun mapping(): List<GenericFunction> {
templates add f("mapIndexedTo(destination: C, transform: (Int, T) -> R)") {
inline(true)
doc {
doc { f ->
"""
Appends transformed elements and their indices of the original collection using the given [transform] function
Appends transformed ${f.element}s and their indices in the original ${f.collection} using the given [transform] function
to the given [destination].
"""
}
@@ -185,7 +184,7 @@ fun mapping(): List<GenericFunction> {
inline(true)
exclude(Sequences)
doc { "Returns a single list of all elements yielded from results of [transform] function being invoked on each element of original collection." }
doc { f -> "Returns a single list of all elements yielded from results of [transform] function being invoked on each ${f.element} of original ${f.collection}." }
typeParam("R")
returns("List<R>")
body {
@@ -208,7 +207,7 @@ fun mapping(): List<GenericFunction> {
templates add f("flatMapTo(destination: C, transform: (T) -> Iterable<R>)") {
inline(true)
exclude(Sequences)
doc { "Appends all elements yielded from results of [transform] function being invoked on each element of original collection, to the given [destination]." }
doc { f -> "Appends all elements yielded from results of [transform] function being invoked on each ${f.element} of original ${f.collection}, to the given [destination]." }
typeParam("R")
typeParam("C : MutableCollection<in R>")
returns("C")
@@ -249,7 +248,7 @@ fun mapping(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns a map of the elements in original collection grouped by the result of given [toKey] function." }
doc { f -> "Returns a map of the ${f.element}s in original ${f.collection} grouped by the result of given [toKey] function." }
typeParam("K")
returns("Map<K, List<T>>")
body { "return groupByTo(LinkedHashMap<K, MutableList<T>>(), toKey)" }
@@ -261,7 +260,7 @@ fun mapping(): List<GenericFunction> {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
typeParam("K")
doc { "Appends elements from original collection grouped by the result of given [toKey] function to the given [map]." }
doc { f -> "Appends ${f.element}s from original ${f.collection} grouped by the result of given [toKey] function to the given [map]." }
returns("Map<K, MutableList<T>>")
body {
"""
@@ -1,6 +1,7 @@
package templates
import templates.Family.*
import templates.DocExtensions.collection
fun numeric(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -8,7 +9,7 @@ fun numeric(): List<GenericFunction> {
templates add f("sum()") {
exclude(Strings)
buildFamilies.forEach { family -> onlyPrimitives(family, numericPrimitives) }
doc { "Returns the sum of all elements in the collection." }
doc { f -> "Returns the sum of all elements in the ${f.collection}." }
returns("SUM")
platformName("sumOf<T>")
body {
@@ -26,7 +27,7 @@ fun numeric(): List<GenericFunction> {
templates add f("average()") {
exclude(Strings)
buildFamilies.forEach { family -> onlyPrimitives(family, numericPrimitives) }
doc { "Returns an average value of elements in the collection."}
doc { f -> "Returns an average value of elements in the ${f.collection}."}
returns("Double")
platformName("averageOf<T>")
body {
@@ -1,13 +1,16 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
import templates.DocExtensions.mapResult
fun sets(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
templates add f("toMutableSet()") {
exclude(Strings)
doc { "Returns a mutable set containing all distinct elements from the given collection." }
doc { f -> "Returns a mutable set containing all distinct ${f.element}s from the given ${f.collection}." }
returns("MutableSet<T>")
body {
"""
@@ -36,28 +39,29 @@ fun sets(): List<GenericFunction> {
templates add f("distinct()") {
exclude(Strings)
val collectionDoc = """
Returns a list containing only distinct elements from the given collection.
The elements in the resulting list are in the same order as they were in the source collection.
doc { f ->
"""
doc { collectionDoc }
Returns a ${f.mapResult} containing only distinct ${f.element}s from the given ${f.collection}.
The ${f.element}s in the resulting ${f.mapResult} are in the same order as they were in the source ${f.collection}.
"""
}
returns("List<T>")
body { "return this.toMutableSet().toList()" }
doc(Sequences) { collectionDoc.replace("list", "sequence").replace("collection", "sequence") }
returns(Sequences) { "Sequence<T>" }
body(Sequences) { "return this.distinctBy { it }" }
}
templates add f("distinctBy(keySelector: (T) -> K)") {
exclude(Strings)
val collectionDoc = """
Returns a list containing only distinct elements from the given collection according to the [keySelector].
The elements in the resulting list are in the same order as they were in the source collection.
doc { f ->
"""
doc { collectionDoc }
Returns a ${f.mapResult} containing only distinct ${f.element}s from the given ${f.collection} according to the [keySelector].
The ${f.element}s in the resulting ${f.mapResult} are in the same order as they were in the source ${f.collection}.
"""
}
inline(true)
typeParam("K")
@@ -76,7 +80,6 @@ fun sets(): List<GenericFunction> {
}
inline(false, Sequences)
doc(Sequences) { collectionDoc.replace("list", "sequence").replace("collection", "sequence") }
returns(Sequences) { "Sequence<T>" }
body(Sequences) {
"""
@@ -1,7 +1,8 @@
package templates
import templates.Family.*
import java.util.ArrayList
import templates.DocExtensions.element
import templates.DocExtensions.collection
fun snapshots(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -9,7 +10,7 @@ fun snapshots(): List<GenericFunction> {
templates add f("toCollection(collection: C)") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Appends all elements to the given [collection]." }
doc { f -> "Appends all ${f.element}s to the given [collection]." }
returns("C")
typeParam("C : MutableCollection<in T>")
body {
@@ -23,7 +24,7 @@ fun snapshots(): List<GenericFunction> {
}
templates add f("toSet()") {
doc { "Returns a [Set] of all elements." }
doc { f -> "Returns a [Set] of all ${f.element}s." }
returns("Set<T>")
body { "return toCollection(LinkedHashSet<T>(mapCapacity(collectionSizeOrDefault(12))))" }
body(Sequences) { "return toCollection(LinkedHashSet<T>())" }
@@ -33,7 +34,7 @@ fun snapshots(): List<GenericFunction> {
}
templates add f("toHashSet()") {
doc { "Returns a [HashSet] of all elements." }
doc { f -> "Returns a [HashSet] of all ${f.element}s." }
returns("HashSet<T>")
body { "return toCollection(HashSet<T>(mapCapacity(collectionSizeOrDefault(12))))" }
body(Sequences) { "return toCollection(HashSet<T>())" }
@@ -45,13 +46,13 @@ fun snapshots(): List<GenericFunction> {
templates add f("toSortedSet()") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns a [SortedSet] of all elements." }
doc { f -> "Returns a [SortedSet] of all ${f.element}s." }
returns("SortedSet<T>")
body { "return toCollection(TreeSet<T>())" }
}
templates add f("toArrayList()") {
doc { "Returns an [ArrayList] of all elements." }
doc { f -> "Returns an [ArrayList] of all ${f.element}s." }
returns("ArrayList<T>")
body { "return toCollection(ArrayList<T>())" }
body(Iterables) {
@@ -91,7 +92,7 @@ fun snapshots(): List<GenericFunction> {
templates add f("toList()") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
doc { "Returns a [List] containing all elements." }
doc { f -> "Returns a [List] containing all ${f.element}s." }
returns("List<T>")
body { "return this.toArrayList()" }
}
@@ -116,10 +117,11 @@ fun snapshots(): List<GenericFunction> {
templates add f("toMapBy(selector: (T) -> K)") {
inline(true)
typeParam("K")
doc {
doc { f ->
"""
Returns Map containing the values from the given collection indexed by [selector].
If any two elements would have the same key returned by [selector] the last one gets added to the map.
Returns Map containing the ${f.element}s from the given ${f.collection} indexed by the key
returned from [selector] function applied to each ${f.element}.
If any two ${f.element}s would have the same key returned by [selector] the last one gets added to the map.
"""
}
returns("Map<K, T>")
@@ -175,10 +177,10 @@ fun snapshots(): List<GenericFunction> {
inline(true)
typeParam("K")
typeParam("V")
doc {
doc { f ->
"""
Returns Map containing the values provided by [transform] and indexed by [selector] from the given collection.
If any two elements would have the same key returned by [selector] the last one gets added to the map.
Returns Map containing the values provided by [transform] and indexed by [selector] functions applied to ${f.element}s of the given ${f.collection}.
If any two ${f.element}s would have the same key returned by [selector] the last one gets added to the map.
"""
}
returns("Map<K, V>")