Files
kotlin-fork/libraries/tools/kotlin-stdlib-gen/src/templates/Numeric.kt
T
2015-04-22 18:21:24 +03:00

26 lines
559 B
Kotlin

package templates
import templates.Family.*
fun numeric(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
templates add f("sum()") {
exclude(Strings)
doc { "Returns the sum of all elements in the collection." }
returns("SUM")
body {
"""
val iterator = iterator()
var sum: SUM = ZERO
while (iterator.hasNext()) {
sum += iterator.next()
}
return sum
"""
}
}
return templates
}