Add missing sum() on Streams.
This commit is contained in:
@@ -19,6 +19,18 @@ public fun Iterable<Int>.sum(): Int {
|
||||
return sum
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Stream<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
|
||||
*/
|
||||
@@ -31,6 +43,18 @@ public fun Iterable<Long>.sum(): Long {
|
||||
return sum
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Stream<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
|
||||
*/
|
||||
@@ -43,6 +67,18 @@ public fun Iterable<Double>.sum(): Double {
|
||||
return sum
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Stream<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
|
||||
*/
|
||||
@@ -55,6 +91,18 @@ public fun Iterable<Float>.sum(): Float {
|
||||
return sum
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
public fun Stream<Float>.sum(): Float {
|
||||
val iterator = iterator()
|
||||
var sum: Float = 0.0f
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all elements in the collection
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user