Generate additional sources for JS instead of copying them from JVM

This commit is contained in:
Ilya Gorbunov
2016-12-03 03:11:00 +03:00
parent bc2d7dda2c
commit 6ea1cde449
17 changed files with 19135 additions and 713 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,203 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("MapsKt")
package kotlin.collections
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.comparisons.*
/**
* Returns a [List] containing all key-value pairs.
*/
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 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 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 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 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 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 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].
*/
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
return true
}
/**
* Returns `true` if map has at least one entry.
*/
public fun <K, V> Map<out K, V>.any(): Boolean {
for (element in this) return true
return false
}
/**
* Returns `true` if at least one entry matches the given [predicate].
*/
public inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
return false
}
/**
* Returns the number of entries in this map.
*/
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<out K, V>.count(): Int {
return size
}
/**
* Returns the number of entries matching the given [predicate].
*/
public inline fun <K, V> Map<out K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int {
var count = 0
for (element in this) if (predicate(element)) count++
return count
}
/**
* Performs the given [action] on each entry.
*/
@kotlin.internal.HidesMembers
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 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 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 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 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.
*/
public fun <K, V> Map<out K, V>.none(): Boolean {
for (element in this) return false
return true
}
/**
* Returns `true` if no entries match the given [predicate].
*/
public inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
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 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 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 fun <K, V> Map<out K, V>.asSequence(): Sequence<Map.Entry<K, V>> {
return entries.asSequence()
}
@@ -0,0 +1,932 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("RangesKt")
package kotlin.ranges
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.comparisons.*
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("intRangeContains")
public operator fun ClosedRange<Int>.contains(value: Byte): Boolean {
return contains(value.toInt())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("longRangeContains")
public operator fun ClosedRange<Long>.contains(value: Byte): Boolean {
return contains(value.toLong())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("shortRangeContains")
public operator fun ClosedRange<Short>.contains(value: Byte): Boolean {
return contains(value.toShort())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("doubleRangeContains")
public operator fun ClosedRange<Double>.contains(value: Byte): Boolean {
return contains(value.toDouble())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("floatRangeContains")
public operator fun ClosedRange<Float>.contains(value: Byte): Boolean {
return contains(value.toFloat())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("intRangeContains")
public operator fun ClosedRange<Int>.contains(value: Double): Boolean {
return value.toIntExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("longRangeContains")
public operator fun ClosedRange<Long>.contains(value: Double): Boolean {
return value.toLongExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("byteRangeContains")
public operator fun ClosedRange<Byte>.contains(value: Double): Boolean {
return value.toByteExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("shortRangeContains")
public operator fun ClosedRange<Short>.contains(value: Double): Boolean {
return value.toShortExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("floatRangeContains")
public operator fun ClosedRange<Float>.contains(value: Double): Boolean {
return contains(value.toFloat())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("intRangeContains")
public operator fun ClosedRange<Int>.contains(value: Float): Boolean {
return value.toIntExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("longRangeContains")
public operator fun ClosedRange<Long>.contains(value: Float): Boolean {
return value.toLongExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("byteRangeContains")
public operator fun ClosedRange<Byte>.contains(value: Float): Boolean {
return value.toByteExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("shortRangeContains")
public operator fun ClosedRange<Short>.contains(value: Float): Boolean {
return value.toShortExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("doubleRangeContains")
public operator fun ClosedRange<Double>.contains(value: Float): Boolean {
return contains(value.toDouble())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("longRangeContains")
public operator fun ClosedRange<Long>.contains(value: Int): Boolean {
return contains(value.toLong())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("byteRangeContains")
public operator fun ClosedRange<Byte>.contains(value: Int): Boolean {
return value.toByteExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("shortRangeContains")
public operator fun ClosedRange<Short>.contains(value: Int): Boolean {
return value.toShortExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("doubleRangeContains")
public operator fun ClosedRange<Double>.contains(value: Int): Boolean {
return contains(value.toDouble())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("floatRangeContains")
public operator fun ClosedRange<Float>.contains(value: Int): Boolean {
return contains(value.toFloat())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("intRangeContains")
public operator fun ClosedRange<Int>.contains(value: Long): Boolean {
return value.toIntExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("byteRangeContains")
public operator fun ClosedRange<Byte>.contains(value: Long): Boolean {
return value.toByteExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("shortRangeContains")
public operator fun ClosedRange<Short>.contains(value: Long): Boolean {
return value.toShortExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("doubleRangeContains")
public operator fun ClosedRange<Double>.contains(value: Long): Boolean {
return contains(value.toDouble())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("floatRangeContains")
public operator fun ClosedRange<Float>.contains(value: Long): Boolean {
return contains(value.toFloat())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("intRangeContains")
public operator fun ClosedRange<Int>.contains(value: Short): Boolean {
return contains(value.toInt())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("longRangeContains")
public operator fun ClosedRange<Long>.contains(value: Short): Boolean {
return contains(value.toLong())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("byteRangeContains")
public operator fun ClosedRange<Byte>.contains(value: Short): Boolean {
return value.toByteExactOrNull().let { if (it != null) contains(it) else false }
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("doubleRangeContains")
public operator fun ClosedRange<Double>.contains(value: Short): Boolean {
return contains(value.toDouble())
}
/**
* Checks if the specified [value] belongs to this range.
*/
@kotlin.jvm.JvmName("floatRangeContains")
public operator fun ClosedRange<Float>.contains(value: Short): Boolean {
return contains(value.toFloat())
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Int.downTo(to: Byte): IntProgression {
return IntProgression.fromClosedRange(this, to.toInt(), -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Long.downTo(to: Byte): LongProgression {
return LongProgression.fromClosedRange(this, to.toLong(), -1L)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Byte.downTo(to: Byte): IntProgression {
return IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Short.downTo(to: Byte): IntProgression {
return IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Char.downTo(to: Char): CharProgression {
return CharProgression.fromClosedRange(this, to, -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Int.downTo(to: Int): IntProgression {
return IntProgression.fromClosedRange(this, to, -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Long.downTo(to: Int): LongProgression {
return LongProgression.fromClosedRange(this, to.toLong(), -1L)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Byte.downTo(to: Int): IntProgression {
return IntProgression.fromClosedRange(this.toInt(), to, -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Short.downTo(to: Int): IntProgression {
return IntProgression.fromClosedRange(this.toInt(), to, -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Int.downTo(to: Long): LongProgression {
return LongProgression.fromClosedRange(this.toLong(), to, -1L)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Long.downTo(to: Long): LongProgression {
return LongProgression.fromClosedRange(this, to, -1L)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Byte.downTo(to: Long): LongProgression {
return LongProgression.fromClosedRange(this.toLong(), to, -1L)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Short.downTo(to: Long): LongProgression {
return LongProgression.fromClosedRange(this.toLong(), to, -1L)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Int.downTo(to: Short): IntProgression {
return IntProgression.fromClosedRange(this, to.toInt(), -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Long.downTo(to: Short): LongProgression {
return LongProgression.fromClosedRange(this, to.toLong(), -1L)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Byte.downTo(to: Short): IntProgression {
return IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*
* The [to] value has to be less than this value.
*/
public infix fun Short.downTo(to: Short): IntProgression {
return IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step.
*/
public fun IntProgression.reversed(): IntProgression {
return IntProgression.fromClosedRange(last, first, -step)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step.
*/
public fun LongProgression.reversed(): LongProgression {
return LongProgression.fromClosedRange(last, first, -step)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step.
*/
public fun CharProgression.reversed(): CharProgression {
return CharProgression.fromClosedRange(last, first, -step)
}
/**
* Returns a progression that goes over the same range with the given step.
*/
public infix fun IntProgression.step(step: Int): IntProgression {
checkStepIsPositive(step > 0, step)
return IntProgression.fromClosedRange(first, last, if (this.step > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step.
*/
public infix fun LongProgression.step(step: Long): LongProgression {
checkStepIsPositive(step > 0, step)
return LongProgression.fromClosedRange(first, last, if (this.step > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step.
*/
public infix fun CharProgression.step(step: Int): CharProgression {
checkStepIsPositive(step > 0, step)
return CharProgression.fromClosedRange(first, last, if (this.step > 0) step else -step)
}
internal fun Int.toByteExactOrNull(): Byte? {
return if (this in Byte.MIN_VALUE.toInt()..Byte.MAX_VALUE.toInt()) this.toByte() else null
}
internal fun Long.toByteExactOrNull(): Byte? {
return if (this in Byte.MIN_VALUE.toLong()..Byte.MAX_VALUE.toLong()) this.toByte() else null
}
internal fun Short.toByteExactOrNull(): Byte? {
return if (this in Byte.MIN_VALUE.toShort()..Byte.MAX_VALUE.toShort()) this.toByte() else null
}
internal fun Double.toByteExactOrNull(): Byte? {
return if (this in Byte.MIN_VALUE.toDouble()..Byte.MAX_VALUE.toDouble()) this.toByte() else null
}
internal fun Float.toByteExactOrNull(): Byte? {
return if (this in Byte.MIN_VALUE.toFloat()..Byte.MAX_VALUE.toFloat()) this.toByte() else null
}
internal fun Long.toIntExactOrNull(): Int? {
return if (this in Int.MIN_VALUE.toLong()..Int.MAX_VALUE.toLong()) this.toInt() else null
}
internal fun Double.toIntExactOrNull(): Int? {
return if (this in Int.MIN_VALUE.toDouble()..Int.MAX_VALUE.toDouble()) this.toInt() else null
}
internal fun Float.toIntExactOrNull(): Int? {
return if (this in Int.MIN_VALUE.toFloat()..Int.MAX_VALUE.toFloat()) this.toInt() else null
}
internal fun Double.toLongExactOrNull(): Long? {
return if (this in Long.MIN_VALUE.toDouble()..Long.MAX_VALUE.toDouble()) this.toLong() else null
}
internal fun Float.toLongExactOrNull(): Long? {
return if (this in Long.MIN_VALUE.toFloat()..Long.MAX_VALUE.toFloat()) this.toLong() else null
}
internal fun Int.toShortExactOrNull(): Short? {
return if (this in Short.MIN_VALUE.toInt()..Short.MAX_VALUE.toInt()) this.toShort() else null
}
internal fun Long.toShortExactOrNull(): Short? {
return if (this in Short.MIN_VALUE.toLong()..Short.MAX_VALUE.toLong()) this.toShort() else null
}
internal fun Double.toShortExactOrNull(): Short? {
return if (this in Short.MIN_VALUE.toDouble()..Short.MAX_VALUE.toDouble()) this.toShort() else null
}
internal fun Float.toShortExactOrNull(): Short? {
return if (this in Short.MIN_VALUE.toFloat()..Short.MAX_VALUE.toFloat()) this.toShort() else null
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Int.until(to: Byte): IntRange {
return this .. (to.toInt() - 1).toInt()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Long.until(to: Byte): LongRange {
return this .. (to.toLong() - 1).toLong()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Byte.until(to: Byte): IntRange {
return this.toInt() .. (to.toInt() - 1).toInt()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Short.until(to: Byte): IntRange {
return this.toInt() .. (to.toInt() - 1).toInt()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*
* If the [to] value is less than or equal to ['\u0000'] the returned range is empty.
*/
public infix fun Char.until(to: Char): CharRange {
if (to <= '\u0000') return CharRange.EMPTY
return this .. (to - 1).toChar()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*
* If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty.
*/
public infix fun Int.until(to: Int): IntRange {
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
return this .. (to - 1).toInt()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Long.until(to: Int): LongRange {
return this .. (to.toLong() - 1).toLong()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*
* If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty.
*/
public infix fun Byte.until(to: Int): IntRange {
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
return this.toInt() .. (to - 1).toInt()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*
* If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty.
*/
public infix fun Short.until(to: Int): IntRange {
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
return this.toInt() .. (to - 1).toInt()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*
* If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty.
*/
public infix fun Int.until(to: Long): LongRange {
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
return this.toLong() .. (to - 1).toLong()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*
* If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty.
*/
public infix fun Long.until(to: Long): LongRange {
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
return this .. (to - 1).toLong()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*
* If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty.
*/
public infix fun Byte.until(to: Long): LongRange {
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
return this.toLong() .. (to - 1).toLong()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*
* If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty.
*/
public infix fun Short.until(to: Long): LongRange {
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
return this.toLong() .. (to - 1).toLong()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Int.until(to: Short): IntRange {
return this .. (to.toInt() - 1).toInt()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Long.until(to: Short): LongRange {
return this .. (to.toLong() - 1).toLong()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Byte.until(to: Short): IntRange {
return this.toInt() .. (to.toInt() - 1).toInt()
}
/**
* Returns a range from this value up to but excluding the specified [to] value.
*/
public infix fun Short.until(to: Short): IntRange {
return this.toInt() .. (to.toInt() - 1).toInt()
}
/**
* Ensures that this value is not less than the specified [minimumValue].
*
* @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
*/
public fun <T: Comparable<T>> T.coerceAtLeast(minimumValue: T): T {
return if (this < minimumValue) minimumValue else this
}
/**
* Ensures that this value is not less than the specified [minimumValue].
*
* @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
*/
public fun Byte.coerceAtLeast(minimumValue: Byte): Byte {
return if (this < minimumValue) minimumValue else this
}
/**
* Ensures that this value is not less than the specified [minimumValue].
*
* @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
*/
public fun Short.coerceAtLeast(minimumValue: Short): Short {
return if (this < minimumValue) minimumValue else this
}
/**
* Ensures that this value is not less than the specified [minimumValue].
*
* @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
*/
public fun Int.coerceAtLeast(minimumValue: Int): Int {
return if (this < minimumValue) minimumValue else this
}
/**
* Ensures that this value is not less than the specified [minimumValue].
*
* @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
*/
public fun Long.coerceAtLeast(minimumValue: Long): Long {
return if (this < minimumValue) minimumValue else this
}
/**
* Ensures that this value is not less than the specified [minimumValue].
*
* @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
*/
public fun Float.coerceAtLeast(minimumValue: Float): Float {
return if (this < minimumValue) minimumValue else this
}
/**
* Ensures that this value is not less than the specified [minimumValue].
*
* @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
*/
public fun Double.coerceAtLeast(minimumValue: Double): Double {
return if (this < minimumValue) minimumValue else this
}
/**
* Ensures that this value is not greater than the specified [maximumValue].
*
* @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
*/
public fun <T: Comparable<T>> T.coerceAtMost(maximumValue: T): T {
return if (this > maximumValue) maximumValue else this
}
/**
* Ensures that this value is not greater than the specified [maximumValue].
*
* @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
*/
public fun Byte.coerceAtMost(maximumValue: Byte): Byte {
return if (this > maximumValue) maximumValue else this
}
/**
* Ensures that this value is not greater than the specified [maximumValue].
*
* @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
*/
public fun Short.coerceAtMost(maximumValue: Short): Short {
return if (this > maximumValue) maximumValue else this
}
/**
* Ensures that this value is not greater than the specified [maximumValue].
*
* @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
*/
public fun Int.coerceAtMost(maximumValue: Int): Int {
return if (this > maximumValue) maximumValue else this
}
/**
* Ensures that this value is not greater than the specified [maximumValue].
*
* @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
*/
public fun Long.coerceAtMost(maximumValue: Long): Long {
return if (this > maximumValue) maximumValue else this
}
/**
* Ensures that this value is not greater than the specified [maximumValue].
*
* @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
*/
public fun Float.coerceAtMost(maximumValue: Float): Float {
return if (this > maximumValue) maximumValue else this
}
/**
* Ensures that this value is not greater than the specified [maximumValue].
*
* @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
*/
public fun Double.coerceAtMost(maximumValue: Double): Double {
return if (this > maximumValue) maximumValue else this
}
/**
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
*/
public fun <T: Comparable<T>> T.coerceIn(minimumValue: T?, maximumValue: T?): T {
if (minimumValue !== null && maximumValue !== null) {
if (minimumValue > maximumValue) throw IllegalArgumentException("Cannot coerce value to an empty range: maximum $maximumValue is less than minimum $minimumValue.")
if (this < minimumValue) return minimumValue
if (this > maximumValue) return maximumValue
}
else {
if (minimumValue !== null && this < minimumValue) return minimumValue
if (maximumValue !== null && this > maximumValue) return maximumValue
}
return this
}
/**
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
*/
public fun Byte.coerceIn(minimumValue: Byte, maximumValue: Byte): Byte {
if (minimumValue > maximumValue) throw IllegalArgumentException("Cannot coerce value to an empty range: maximum $maximumValue is less than minimum $minimumValue.")
if (this < minimumValue) return minimumValue
if (this > maximumValue) return maximumValue
return this
}
/**
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
*/
public fun Short.coerceIn(minimumValue: Short, maximumValue: Short): Short {
if (minimumValue > maximumValue) throw IllegalArgumentException("Cannot coerce value to an empty range: maximum $maximumValue is less than minimum $minimumValue.")
if (this < minimumValue) return minimumValue
if (this > maximumValue) return maximumValue
return this
}
/**
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
*/
public fun Int.coerceIn(minimumValue: Int, maximumValue: Int): Int {
if (minimumValue > maximumValue) throw IllegalArgumentException("Cannot coerce value to an empty range: maximum $maximumValue is less than minimum $minimumValue.")
if (this < minimumValue) return minimumValue
if (this > maximumValue) return maximumValue
return this
}
/**
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
*/
public fun Long.coerceIn(minimumValue: Long, maximumValue: Long): Long {
if (minimumValue > maximumValue) throw IllegalArgumentException("Cannot coerce value to an empty range: maximum $maximumValue is less than minimum $minimumValue.")
if (this < minimumValue) return minimumValue
if (this > maximumValue) return maximumValue
return this
}
/**
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
*/
public fun Float.coerceIn(minimumValue: Float, maximumValue: Float): Float {
if (minimumValue > maximumValue) throw IllegalArgumentException("Cannot coerce value to an empty range: maximum $maximumValue is less than minimum $minimumValue.")
if (this < minimumValue) return minimumValue
if (this > maximumValue) return maximumValue
return this
}
/**
* Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
*
* @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
*/
public fun Double.coerceIn(minimumValue: Double, maximumValue: Double): Double {
if (minimumValue > maximumValue) throw IllegalArgumentException("Cannot coerce value to an empty range: maximum $maximumValue is less than minimum $minimumValue.")
if (this < minimumValue) return minimumValue
if (this > maximumValue) return maximumValue
return this
}
/**
* Ensures that this value lies in the specified [range].
*
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public fun <T: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): T {
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return when {
// this < start equiv to this <= start && !(this >= start)
range.lessThanOrEquals(this, range.start) && !range.lessThanOrEquals(range.start, this) -> range.start
// this > end equiv to this >= end && !(this <= end)
range.lessThanOrEquals(range.endInclusive, this) && !range.lessThanOrEquals(this, range.endInclusive) -> range.endInclusive
else -> this
}
}
/**
* Ensures that this value lies in the specified [range].
*
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public fun <T: Comparable<T>> T.coerceIn(range: ClosedRange<T>): T {
if (range is ClosedComparableRange) {
return this.coerceIn<T>(range)
}
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return when {
this < range.start -> range.start
this > range.endInclusive -> range.endInclusive
else -> this
}
}
/**
* Ensures that this value lies in the specified [range].
*
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public fun Int.coerceIn(range: ClosedRange<Int>): Int {
if (range is ClosedComparableRange) {
return this.coerceIn<Int>(range)
}
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return when {
this < range.start -> range.start
this > range.endInclusive -> range.endInclusive
else -> this
}
}
/**
* Ensures that this value lies in the specified [range].
*
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public fun Long.coerceIn(range: ClosedRange<Long>): Long {
if (range is ClosedComparableRange) {
return this.coerceIn<Long>(range)
}
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return when {
this < range.start -> range.start
this > range.endInclusive -> range.endInclusive
else -> this
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,131 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("SetsKt")
package kotlin.collections
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.comparisons.*
/**
* Returns a set containing all elements of the original set except the given [element].
*
* The returned set preserves the element iteration order of the original set.
*/
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 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 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 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].
*
* The returned set preserves the element iteration order of the original set.
*/
@kotlin.internal.InlineOnly
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 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,
* which aren't already in this set.
*
* The returned set preserves the element iteration order of the original set.
*/
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 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,
* which aren't already in this set.
*
* The returned set preserves the element iteration order of the original set.
*/
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.
*
* The returned set preserves the element iteration order of the original set.
*/
@kotlin.internal.InlineOnly
public inline fun <T> Set<T>.plusElement(element: T): Set<T> {
return plus(element)
}
File diff suppressed because it is too large Load Diff
+301 -300
View File
@@ -1,5 +1,6 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("ArraysKt")
@file:kotlin.jvm.JvmVersion
package kotlin.collections
@@ -12599,6 +12600,306 @@ public fun CharArray.asSequence(): Sequence<Char> {
return Sequence { this.iterator() }
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfByte")
public fun Array<out Byte>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfShort")
public fun Array<out Short>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfInt")
public fun Array<out Int>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfLong")
public fun Array<out Long>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfFloat")
public fun Array<out Float>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfDouble")
public fun Array<out Double>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun ByteArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun ShortArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun IntArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun LongArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun FloatArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun DoubleArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfByte")
public fun Array<out Byte>.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfShort")
public fun Array<out Short>.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfInt")
public fun Array<out Int>.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfLong")
public fun Array<out Long>.sum(): Long {
var sum: Long = 0L
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfFloat")
public fun Array<out Float>.sum(): Float {
var sum: Float = 0.0f
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfDouble")
public fun Array<out Double>.sum(): Double {
var sum: Double = 0.0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun ByteArray.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun ShortArray.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun IntArray.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun LongArray.sum(): Long {
var sum: Long = 0L
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun FloatArray.sum(): Float {
var sum: Float = 0.0f
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun DoubleArray.sum(): Double {
var sum: Double = 0.0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns a [List] that wraps the original array.
*/
@@ -13759,303 +14060,3 @@ public fun CharArray.toTypedArray(): Array<Char> {
return result as Array<Char>
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfByte")
public fun Array<out Byte>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfShort")
public fun Array<out Short>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfInt")
public fun Array<out Int>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfLong")
public fun Array<out Long>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfFloat")
public fun Array<out Float>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
@kotlin.jvm.JvmName("averageOfDouble")
public fun Array<out Double>.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun ByteArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun ShortArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun IntArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun LongArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun FloatArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns an average value of elements in the array.
*/
public fun DoubleArray.average(): Double {
var sum: Double = 0.0
var count: Int = 0
for (element in this) {
sum += element
count += 1
}
return if (count == 0) 0.0 else sum / count
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfByte")
public fun Array<out Byte>.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfShort")
public fun Array<out Short>.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfInt")
public fun Array<out Int>.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfLong")
public fun Array<out Long>.sum(): Long {
var sum: Long = 0L
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfFloat")
public fun Array<out Float>.sum(): Float {
var sum: Float = 0.0f
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
@kotlin.jvm.JvmName("sumOfDouble")
public fun Array<out Double>.sum(): Double {
var sum: Double = 0.0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun ByteArray.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun ShortArray.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun IntArray.sum(): Int {
var sum: Int = 0
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun LongArray.sum(): Long {
var sum: Long = 0L
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun FloatArray.sum(): Float {
var sum: Float = 0.0f
for (element in this) {
sum += element
}
return sum
}
/**
* Returns the sum of all elements in the array.
*/
public fun DoubleArray.sum(): Double {
var sum: Double = 0.0
for (element in this) {
sum += element
}
return sum
}
+19 -18
View File
@@ -1,5 +1,6 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("CollectionsKt")
@file:kotlin.jvm.JvmVersion
package kotlin.collections
@@ -1959,24 +1960,6 @@ public fun <T> Iterable<T>.asSequence(): Sequence<T> {
return Sequence { this.iterator() }
}
/**
* Returns a list containing all elements that are instances of specified class.
*/
@kotlin.jvm.JvmVersion
public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
return filterIsInstanceTo(ArrayList<R>(), klass)
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
@kotlin.jvm.JvmVersion
public fun <C : MutableCollection<in R>, R> Iterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
/**
* Returns an average value of elements in the collection.
*/
@@ -2133,3 +2116,21 @@ public fun Iterable<Double>.sum(): Double {
return sum
}
/**
* Returns a list containing all elements that are instances of specified class.
*/
@kotlin.jvm.JvmVersion
public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
return filterIsInstanceTo(ArrayList<R>(), klass)
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
@kotlin.jvm.JvmVersion
public fun <C : MutableCollection<in R>, R> Iterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
+1
View File
@@ -1,5 +1,6 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("MapsKt")
@file:kotlin.jvm.JvmVersion
package kotlin.collections
@@ -1,5 +1,6 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("RangesKt")
@file:kotlin.jvm.JvmVersion
package kotlin.ranges
+20 -19
View File
@@ -1,5 +1,6 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("SequencesKt")
@file:kotlin.jvm.JvmVersion
package kotlin.sequences
@@ -1237,25 +1238,6 @@ public inline fun <T> Sequence<T>.asSequence(): Sequence<T> {
return this
}
/**
* Returns a sequence containing all elements that are instances of specified class.
*/
@kotlin.jvm.JvmVersion
public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
@Suppress("UNCHECKED_CAST")
return filter { klass.isInstance(it) } as Sequence<R>
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
@kotlin.jvm.JvmVersion
public fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
/**
* Returns an average value of elements in the sequence.
*/
@@ -1412,3 +1394,22 @@ public fun Sequence<Double>.sum(): Double {
return sum
}
/**
* Returns a sequence containing all elements that are instances of specified class.
*/
@kotlin.jvm.JvmVersion
public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
@Suppress("UNCHECKED_CAST")
return filter { klass.isInstance(it) } as Sequence<R>
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
@kotlin.jvm.JvmVersion
public fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
+1
View File
@@ -1,5 +1,6 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("SetsKt")
@file:kotlin.jvm.JvmVersion
package kotlin.collections
@@ -1,5 +1,6 @@
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("StringsKt")
@file:kotlin.jvm.JvmVersion
package kotlin.text
@@ -31,54 +31,63 @@ fun main(args: Array<String>) {
}
fun generateCollectionsAPI(outDir: File) {
val templates = sequenceOf(
::elements,
::filtering,
::ordering,
::arrays,
::snapshots,
::mapping,
::sets,
::aggregates,
::guards,
::generators,
::strings,
::sequences,
::specialJVM,
::ranges,
::numeric,
::comparables
).flatMap { it().sortedBy { it.signature }.asSequence() }
val commonGenerators = sequenceOf(
::elements,
::filtering,
::ordering,
::arrays,
::snapshots,
::mapping,
::sets,
::aggregates,
::guards,
::generators,
::strings,
::sequences,
::ranges,
::numeric,
::comparables
)
templates.groupByFileAndWrite(outDir)
fun generateCollectionsAPI(outDir: File) {
val templates = (commonGenerators + ::specialJVM).flatMap { it().sortedBy { it.signature }.asSequence() }
templates.groupByFileAndWrite(outDir, Platform.JVM)
}
fun generateCollectionsJsAPI(outDir: File) {
specialJS().asSequence().groupByFileAndWrite(outDir, { "_${it.name.capitalize()}Js.kt"})
(commonGenerators + ::specialJS).flatMap { it().sortedBy { it.signature }.asSequence() }
.groupByFileAndWrite(outDir, Platform.JS, { "_${it.name.capitalize()}Js.kt"})
}
private fun Sequence<GenericFunction>.groupByFileAndWrite(
outDir: File,
platform: Platform,
fileNameBuilder: (SourceFile) -> String = { "_${it.name.capitalize()}.kt" }
) {
val groupedConcreteFunctions = flatMap { it.instantiate().asSequence() }.groupBy { it.sourceFile }
val groupedConcreteFunctions = map { it.instantiate(platform) }.flatten().groupBy { it.sourceFile }
for ((sourceFile, functions) in groupedConcreteFunctions) {
val file = outDir.resolve(fileNameBuilder(sourceFile))
functions.writeTo(file, sourceFile)
functions.writeTo(file, sourceFile, platform)
}
}
private fun List<ConcreteFunction>.writeTo(file: File, sourceFile: SourceFile) {
private fun List<ConcreteFunction>.writeTo(file: File, sourceFile: SourceFile, platform: Platform) {
println("Generating file: $file")
FileWriter(file).use { writer ->
if (sourceFile.multifile) {
writer.append("@file:kotlin.jvm.JvmMultifileClass\n")
writer.appendln("@file:kotlin.jvm.JvmMultifileClass")
}
writer.append("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")\n\n")
writer.appendln("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")")
if (platform == Platform.JVM)
writer.appendln("@file:kotlin.jvm.JvmVersion")
writer.appendln()
writer.append("package ${sourceFile.packageName ?: "kotlin"}\n\n")
writer.append("$COMMON_AUTOGENERATED_WARNING\n\n")
writer.append("import kotlin.comparisons.*\n\n")
@@ -269,6 +269,16 @@ fun specialJVM(): List<GenericFunction> {
}
"""
}
//
// body(ArraysOfObjects) {
// """
// return ArrayList<T>(this.unsafeCast<Array<Any?>>())
// """
// }
//
// inline(true, ArraysOfPrimitives)
// body(ArraysOfPrimitives) {"""return this.unsafeCast<Array<T>>().asList()"""}
}
templates add f("toTypedArray()") {
@@ -288,6 +298,11 @@ fun specialJVM(): List<GenericFunction> {
return result as Array<T>
"""
}
// body {
// """
// return copyOf().unsafeCast<Array<T>>()
// """
// }
}
templates.forEach { it.apply { jvmOnly(true) } }
@@ -70,6 +70,11 @@ enum class Inline {
fun isInline() = this != No
}
enum class Platform {
JVM,
JS
}
data class Deprecation(val message: String, val replaceWith: String? = null, val level: DeprecationLevel = DeprecationLevel.WARNING)
val forBinaryCompatibility = Deprecation("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@@ -100,6 +105,9 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
open class FamilyProperty<TValue: Any>() : SpecializedProperty<Family, TValue>()
open class PrimitiveProperty<TValue: Any>() : SpecializedProperty<PrimitiveType, TValue>()
//
// operator fun <TValue : Any> FamilyProperty<TValue>.invoke(vararg keys: Family, valueBuilder: (Family) -> TValue) = set(keys.map { null to it }, valueBuilder)
// operator fun <TKey: Any, TValue : Any> SpecializedProperty<TKey, TValue>.invoke(value: TValue, vararg keys: TKey) = set(keys.asList(), { value })
class DeprecationProperty() : FamilyProperty<Deprecation>()
operator fun DeprecationProperty.invoke(value: String, vararg keys: Family) = set(keys.asList(), { Deprecation(value) })
@@ -207,10 +215,11 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
buildPrimitives.addAll(p.toList())
}
fun instantiate(vararg families: Family = Family.values()): List<ConcreteFunction> {
fun instantiate(platform: Platform, vararg families: Family = Family.values()): List<ConcreteFunction> {
return families
.sortedBy { it.ordinal }
.filter { buildFamilies.contains(it) }
.filter { platform == Platform.JVM || jvmOnly[it] != true }
.flatMap { family -> instantiate(family) }
}