Generate sum() methods for arrays, iterables and sequences of Byte and Short. These overloads got explicit platformName.

Heuristics to decide when to set platformName.
#KT-3714
This commit is contained in:
Ilya Gorbunov
2015-04-15 23:14:46 +03:00
parent ccc3646bb8
commit 9759be5493
21 changed files with 270 additions and 145 deletions
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
+235 -134
View File
@@ -5,13 +5,15 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfInt")
public fun Iterable<Int>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
@@ -22,8 +24,9 @@ public fun Iterable<Int>.sum(): Int {
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfInt")
public fun Sequence<Int>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
@@ -36,8 +39,9 @@ public fun Sequence<Int>.sum(): Int {
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfInt")
public fun Stream<Int>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
@@ -48,8 +52,34 @@ public fun Stream<Int>.sum(): Int {
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfInt")
public fun Array<out Int>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
public fun IntArray.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfLong")
public fun Iterable<Long>.sum(): Long {
val iterator = iterator()
var sum: Long = 0
@@ -60,8 +90,9 @@ public fun Iterable<Long>.sum(): Long {
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfLong")
public fun Sequence<Long>.sum(): Long {
val iterator = iterator()
var sum: Long = 0
@@ -74,8 +105,9 @@ public fun Sequence<Long>.sum(): Long {
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfLong")
public fun Stream<Long>.sum(): Long {
val iterator = iterator()
var sum: Long = 0
@@ -86,8 +118,166 @@ public fun Stream<Long>.sum(): Long {
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfLong")
public fun Array<out Long>.sum(): Long {
val iterator = iterator()
var sum: Long = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
public fun LongArray.sum(): Long {
val iterator = iterator()
var sum: Long = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfByte")
public fun Iterable<Byte>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfByte")
public fun Sequence<Byte>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfByte")
public fun Stream<Byte>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfByte")
public fun Array<out Byte>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
public fun ByteArray.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfShort")
public fun Iterable<Short>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfShort")
public fun Sequence<Short>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfShort")
public fun Stream<Short>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfShort")
public fun Array<out Short>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
public fun ShortArray.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfDouble")
public fun Iterable<Double>.sum(): Double {
val iterator = iterator()
var sum: Double = 0.0
@@ -98,8 +288,9 @@ public fun Iterable<Double>.sum(): Double {
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfDouble")
public fun Sequence<Double>.sum(): Double {
val iterator = iterator()
var sum: Double = 0.0
@@ -112,8 +303,9 @@ public fun Sequence<Double>.sum(): Double {
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfDouble")
public fun Stream<Double>.sum(): Double {
val iterator = iterator()
var sum: Double = 0.0
@@ -124,8 +316,34 @@ public fun Stream<Double>.sum(): Double {
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfDouble")
public fun Array<out Double>.sum(): Double {
val iterator = iterator()
var sum: Double = 0.0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
public fun DoubleArray.sum(): Double {
val iterator = iterator()
var sum: Double = 0.0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection.
*/
platformName("sumOfFloat")
public fun Iterable<Float>.sum(): Float {
val iterator = iterator()
var sum: Float = 0.0f
@@ -136,8 +354,9 @@ public fun Iterable<Float>.sum(): Float {
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfFloat")
public fun Sequence<Float>.sum(): Float {
val iterator = iterator()
var sum: Float = 0.0f
@@ -150,8 +369,9 @@ public fun Sequence<Float>.sum(): Float {
deprecated("Migrate to using Sequence<T> and respective functions")
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfFloat")
public fun Stream<Float>.sum(): Float {
val iterator = iterator()
var sum: Float = 0.0f
@@ -162,128 +382,9 @@ public fun Stream<Float>.sum(): Float {
}
/**
* Returns the sum of all elements in the collection
*/
public fun Array<out Int>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun IntArray.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun Array<out Long>.sum(): Long {
val iterator = iterator()
var sum: Long = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun LongArray.sum(): Long {
val iterator = iterator()
var sum: Long = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun Array<out Byte>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun ByteArray.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun Array<out Short>.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun ShortArray.sum(): Int {
val iterator = iterator()
var sum: Int = 0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun Array<out Double>.sum(): Double {
val iterator = iterator()
var sum: Double = 0.0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
*/
public fun DoubleArray.sum(): Double {
val iterator = iterator()
var sum: Double = 0.0
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
platformName("sumOfFloat")
public fun Array<out Float>.sum(): Float {
val iterator = iterator()
var sum: Float = 0.0f
@@ -294,7 +395,7 @@ public fun Array<out Float>.sum(): Float {
}
/**
* Returns the sum of all elements in the collection
* Returns the sum of all elements in the collection.
*/
public fun FloatArray.sum(): Float {
val iterator = iterator()
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
+1
View File
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
@@ -5,6 +5,7 @@ package kotlin
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.platform.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js