Files
kotlin/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realIteratorFoldl.kt

14 lines
465 B
Kotlin
Vendored

// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND_WITHOUT_CHECK: JS
tailrec 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"
}