Switch to the new stdlib source generation scheme

Remove old generated sources for stdlib-jvm and stdlib-js
This commit is contained in:
Ilya Gorbunov
2017-11-22 07:14:33 +03:00
parent ae62cd6570
commit 69ebb3bfb0
34 changed files with 12985 additions and 44466 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -17,7 +17,9 @@ import kotlin.comparisons.*
* If values are equal, returns the first one.
*/
@SinceKotlin("1.1")
public expect fun <T: Comparable<T>> maxOf(a: T, b: T): T
public fun <T: Comparable<T>> maxOf(a: T, b: T): T {
return if (a >= b) a else b
}
/**
* Returns the greater of two values.
@@ -65,7 +67,9 @@ public expect inline fun maxOf(a: Double, b: Double): Double
* Returns the greater of three values.
*/
@SinceKotlin("1.1")
public expect fun <T: Comparable<T>> maxOf(a: T, b: T, c: T): T
public fun <T: Comparable<T>> maxOf(a: T, b: T, c: T): T {
return maxOf(a, maxOf(b, c))
}
/**
* Returns the greater of three values.
@@ -93,7 +97,9 @@ public expect inline fun maxOf(a: Int, b: Int, c: Int): Int
*/
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public expect inline fun maxOf(a: Long, b: Long, c: Long): Long
public inline fun maxOf(a: Long, b: Long, c: Long): Long {
return maxOf(a, maxOf(b, c))
}
/**
* Returns the greater of three values.
@@ -113,21 +119,27 @@ public expect inline fun maxOf(a: Double, b: Double, c: Double): Double
* Returns the greater of three values according to the order specified by the given [comparator].
*/
@SinceKotlin("1.1")
public expect fun <T> maxOf(a: T, b: T, c: T, comparator: Comparator<in T>): T
public fun <T> maxOf(a: T, b: T, c: T, comparator: Comparator<in T>): T {
return maxOf(a, maxOf(b, c, comparator), comparator)
}
/**
* Returns the greater of two values according to the order specified by the given [comparator].
* If values are equal, returns the first one.
*/
@SinceKotlin("1.1")
public expect fun <T> maxOf(a: T, b: T, comparator: Comparator<in T>): T
public fun <T> maxOf(a: T, b: T, comparator: Comparator<in T>): T {
return if (comparator.compare(a, b) >= 0) a else b
}
/**
* Returns the smaller of two values.
* If values are equal, returns the first one.
*/
@SinceKotlin("1.1")
public expect fun <T: Comparable<T>> minOf(a: T, b: T): T
public fun <T: Comparable<T>> minOf(a: T, b: T): T {
return if (a <= b) a else b
}
/**
* Returns the smaller of two values.
@@ -175,7 +187,9 @@ public expect inline fun minOf(a: Double, b: Double): Double
* Returns the smaller of three values.
*/
@SinceKotlin("1.1")
public expect fun <T: Comparable<T>> minOf(a: T, b: T, c: T): T
public fun <T: Comparable<T>> minOf(a: T, b: T, c: T): T {
return minOf(a, minOf(b, c))
}
/**
* Returns the smaller of three values.
@@ -203,7 +217,9 @@ public expect inline fun minOf(a: Int, b: Int, c: Int): Int
*/
@SinceKotlin("1.1")
@kotlin.internal.InlineOnly
public expect inline fun minOf(a: Long, b: Long, c: Long): Long
public inline fun minOf(a: Long, b: Long, c: Long): Long {
return minOf(a, minOf(b, c))
}
/**
* Returns the smaller of three values.
@@ -223,12 +239,16 @@ public expect inline fun minOf(a: Double, b: Double, c: Double): Double
* Returns the smaller of three values according to the order specified by the given [comparator].
*/
@SinceKotlin("1.1")
public expect fun <T> minOf(a: T, b: T, c: T, comparator: Comparator<in T>): T
public fun <T> minOf(a: T, b: T, c: T, comparator: Comparator<in T>): T {
return minOf(a, minOf(b, c, comparator), comparator)
}
/**
* Returns the smaller of two values according to the order specified by the given [comparator].
* If values are equal, returns the first one.
*/
@SinceKotlin("1.1")
public expect fun <T> minOf(a: T, b: T, comparator: Comparator<in T>): T
public fun <T> minOf(a: T, b: T, comparator: Comparator<in T>): T {
return if (comparator.compare(a, b) <= 0) a else b
}
+95 -22
View File
@@ -15,130 +15,203 @@ import kotlin.comparisons.*
/**
* Returns a [List] containing all key-value pairs.
*/
public expect fun <K, V> Map<out K, V>.toList(): List<Pair<K, V>>
public fun <K, V> Map<out K, V>.toList(): List<Pair<K, V>> {
if (size == 0)
return emptyList()
val iterator = entries.iterator()
if (!iterator.hasNext())
return emptyList()
val first = iterator.next()
if (!iterator.hasNext())
return listOf(first.toPair())
val result = ArrayList<Pair<K, V>>(size)
result.add(first.toPair())
do {
result.add(iterator.next().toPair())
} while (iterator.hasNext())
return result
}
/**
* Returns a single list of all elements yielded from results of [transform] function being invoked on each entry of original map.
*/
public expect inline fun <K, V, R> Map<out K, V>.flatMap(transform: (Map.Entry<K, V>) -> Iterable<R>): List<R>
public inline fun <K, V, R> Map<out 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 entry of original map, to the given [destination].
*/
public expect inline fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.flatMapTo(destination: C, transform: (Map.Entry<K, V>) -> Iterable<R>): C
public inline fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.flatMapTo(destination: C, transform: (Map.Entry<K, V>) -> Iterable<R>): C {
for (element in this) {
val list = transform(element)
destination.addAll(list)
}
return destination
}
/**
* Returns a list containing the results of applying the given [transform] function
* to each entry in the original map.
*/
public expect inline fun <K, V, R> Map<out K, V>.map(transform: (Map.Entry<K, V>) -> R): List<R>
public inline fun <K, V, R> Map<out K, V>.map(transform: (Map.Entry<K, V>) -> R): List<R> {
return mapTo(ArrayList<R>(size), transform)
}
/**
* Returns a list containing only the non-null results of applying the given [transform] function
* to each entry in the original map.
*/
public expect inline fun <K, V, R : Any> Map<out K, V>.mapNotNull(transform: (Map.Entry<K, V>) -> R?): List<R>
public inline fun <K, V, R : Any> Map<out K, V>.mapNotNull(transform: (Map.Entry<K, V>) -> R?): List<R> {
return mapNotNullTo(ArrayList<R>(), transform)
}
/**
* Applies the given [transform] function to each entry in the original map
* and appends only the non-null results to the given [destination].
*/
public expect inline fun <K, V, R : Any, C : MutableCollection<in R>> Map<out K, V>.mapNotNullTo(destination: C, transform: (Map.Entry<K, V>) -> R?): C
public inline fun <K, V, R : Any, C : MutableCollection<in R>> Map<out K, V>.mapNotNullTo(destination: C, transform: (Map.Entry<K, V>) -> R?): C {
forEach { element -> transform(element)?.let { destination.add(it) } }
return destination
}
/**
* Applies the given [transform] function to each entry of the original map
* and appends the results to the given [destination].
*/
public expect inline fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.mapTo(destination: C, transform: (Map.Entry<K, V>) -> R): C
public inline fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.mapTo(destination: C, transform: (Map.Entry<K, V>) -> R): C {
for (item in this)
destination.add(transform(item))
return destination
}
/**
* Returns `true` if all entries match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return true
for (element in this) if (!predicate(element)) return false
return true
}
/**
* Returns `true` if map has at least one entry.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun <K, V> Map<out K, V>.any(): Boolean
public fun <K, V> Map<out K, V>.any(): Boolean {
return !isEmpty()
}
/**
* Returns `true` if at least one entry matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean
public inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return false
for (element in this) if (predicate(element)) return true
return false
}
/**
* Returns the number of entries in this map.
*/
@kotlin.internal.InlineOnly
public expect inline fun <K, V> Map<out K, V>.count(): Int
public inline fun <K, V> Map<out K, V>.count(): Int {
return size
}
/**
* Returns the number of entries matching the given [predicate].
*/
public expect inline fun <K, V> Map<out K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int
public inline fun <K, V> Map<out K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int {
if (isEmpty()) return 0
var count = 0
for (element in this) if (predicate(element)) count++
return count
}
/**
* Performs the given [action] on each entry.
*/
@kotlin.internal.HidesMembers
public expect inline fun <K, V> Map<out K, V>.forEach(action: (Map.Entry<K, V>) -> Unit): Unit
public inline fun <K, V> Map<out K, V>.forEach(action: (Map.Entry<K, V>) -> Unit): Unit {
for (element in this) action(element)
}
/**
* Returns the first entry yielding the largest value of the given function or `null` if there are no entries.
*/
@kotlin.internal.InlineOnly
public expect inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>?
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>? {
return entries.maxBy(selector)
}
/**
* Returns the first entry having the largest value according to the provided [comparator] or `null` if there are no entries.
*/
@kotlin.internal.InlineOnly
public expect inline fun <K, V> Map<out K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>?
public inline fun <K, V> Map<out K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
return entries.maxWith(comparator)
}
/**
* Returns the first entry yielding the smallest value of the given function or `null` if there are no entries.
*/
public expect inline fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>?
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>? {
return entries.minBy(selector)
}
/**
* Returns the first entry having the smallest value according to the provided [comparator] or `null` if there are no entries.
*/
public expect fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>?
public fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
return entries.minWith(comparator)
}
/**
* Returns `true` if the map has no entries.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun <K, V> Map<out K, V>.none(): Boolean
public fun <K, V> Map<out K, V>.none(): Boolean {
return isEmpty()
}
/**
* Returns `true` if no entries match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean
public inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return true
for (element in this) if (predicate(element)) return false
return true
}
/**
* Performs the given [action] on each entry and returns the map itself afterwards.
*/
@SinceKotlin("1.1")
public expect inline fun <K, V, M : Map<out K, V>> M.onEach(action: (Map.Entry<K, V>) -> Unit): M
public inline fun <K, V, M : Map<out K, V>> M.onEach(action: (Map.Entry<K, V>) -> Unit): M {
return apply { for (element in this) action(element) }
}
/**
* Creates an [Iterable] instance that wraps the original map returning its entries when being iterated.
*/
@kotlin.internal.InlineOnly
public expect inline fun <K, V> Map<out K, V>.asIterable(): Iterable<Map.Entry<K, V>>
public inline fun <K, V> Map<out K, V>.asIterable(): Iterable<Map.Entry<K, V>> {
return entries
}
/**
* Creates a [Sequence] instance that wraps the original map returning its entries when being iterated.
*/
public expect fun <K, V> Map<out K, V>.asSequence(): Sequence<Map.Entry<K, V>>
public fun <K, V> Map<out K, V>.asSequence(): Sequence<Map.Entry<K, V>> {
return entries.asSequence()
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+55 -10
View File
@@ -17,28 +17,49 @@ import kotlin.comparisons.*
*
* The returned set preserves the element iteration order of the original set.
*/
public expect operator fun <T> Set<T>.minus(element: T): Set<T>
public operator fun <T> Set<T>.minus(element: T): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(size))
var removed = false
return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true }
}
/**
* Returns a set containing all elements of the original set except the elements contained in the given [elements] array.
*
* The returned set preserves the element iteration order of the original set.
*/
public expect operator fun <T> Set<T>.minus(elements: Array<out T>): Set<T>
public operator fun <T> Set<T>.minus(elements: Array<out T>): Set<T> {
val result = LinkedHashSet<T>(this)
result.removeAll(elements)
return result
}
/**
* Returns a set containing all elements of the original set except the elements contained in the given [elements] collection.
*
* The returned set preserves the element iteration order of the original set.
*/
public expect operator fun <T> Set<T>.minus(elements: Iterable<T>): Set<T>
public operator fun <T> Set<T>.minus(elements: Iterable<T>): Set<T> {
val other = elements.convertToSetForSetOperationWith(this)
if (other.isEmpty())
return this.toSet()
if (other is Set)
return this.filterNotTo(LinkedHashSet<T>()) { it in other }
val result = LinkedHashSet<T>(this)
result.removeAll(other)
return result
}
/**
* Returns a set containing all elements of the original set except the elements contained in the given [elements] sequence.
*
* The returned set preserves the element iteration order of the original set.
*/
public expect operator fun <T> Set<T>.minus(elements: Sequence<T>): Set<T>
public operator fun <T> Set<T>.minus(elements: Sequence<T>): Set<T> {
val result = LinkedHashSet<T>(this)
result.removeAll(elements)
return result
}
/**
* Returns a set containing all elements of the original set except the given [element].
@@ -46,14 +67,21 @@ public expect operator fun <T> Set<T>.minus(elements: Sequence<T>): Set<T>
* The returned set preserves the element iteration order of the original set.
*/
@kotlin.internal.InlineOnly
public expect inline fun <T> Set<T>.minusElement(element: T): Set<T>
public inline fun <T> Set<T>.minusElement(element: T): Set<T> {
return minus(element)
}
/**
* Returns a set containing all elements of the original set and then the given [element] if it isn't already in this set.
*
* The returned set preserves the element iteration order of the original set.
*/
public expect operator fun <T> Set<T>.plus(element: T): Set<T>
public operator fun <T> Set<T>.plus(element: T): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(size + 1))
result.addAll(this)
result.add(element)
return result
}
/**
* Returns a set containing all elements of the original set and the given [elements] array,
@@ -61,14 +89,24 @@ public expect operator fun <T> Set<T>.plus(element: T): Set<T>
*
* The returned set preserves the element iteration order of the original set.
*/
public expect operator fun <T> Set<T>.plus(elements: Array<out T>): Set<T>
public operator fun <T> Set<T>.plus(elements: Array<out T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(this.size + elements.size))
result.addAll(this)
result.addAll(elements)
return result
}
/**
* Returns a set containing all elements of the original set and the given [elements] collection,
* which aren't already in this set.
* The returned set preserves the element iteration order of the original set.
*/
public expect operator fun <T> Set<T>.plus(elements: Iterable<T>): Set<T>
public operator fun <T> Set<T>.plus(elements: Iterable<T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(elements.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2))
result.addAll(this)
result.addAll(elements)
return result
}
/**
* Returns a set containing all elements of the original set and the given [elements] sequence,
@@ -76,7 +114,12 @@ public expect operator fun <T> Set<T>.plus(elements: Iterable<T>): Set<T>
*
* The returned set preserves the element iteration order of the original set.
*/
public expect operator fun <T> Set<T>.plus(elements: Sequence<T>): Set<T>
public operator fun <T> Set<T>.plus(elements: Sequence<T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(this.size * 2))
result.addAll(this)
result.addAll(elements)
return result
}
/**
* Returns a set containing all elements of the original set and then the given [element] if it isn't already in this set.
@@ -84,5 +127,7 @@ public expect operator fun <T> Set<T>.plus(elements: Sequence<T>): Set<T>
* The returned set preserves the element iteration order of the original set.
*/
@kotlin.internal.InlineOnly
public expect inline fun <T> Set<T>.plusElement(element: T): Set<T>
public inline fun <T> Set<T>.plusElement(element: T): Set<T> {
return plus(element)
}
File diff suppressed because it is too large Load Diff