Files
kotlin/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realIteratorFoldl.kt
Svetlana Isakova b71260f54e Moved tests
that are used both for codegen & diagnostics to codegen/box/diagnostics
2014-11-21 14:02:45 +03:00

11 lines
363 B
Kotlin

tailRecursive fun <T, A> Iterator<T>.foldl(acc : A, foldFunction : (e : T, acc : A) -> A) : A =
if (!hasNext()) acc
else foldl(foldFunction(next(), acc), foldFunction)
fun box() : String {
val sum = (1..1000000).iterator().foldl(0) { (e : Int, acc : Long) ->
acc + e
}
return if (sum == 500000500000) "OK" else "FAIL: $sum"
}