Files
kotlin-fork/compiler/testData/codegen/box/functions/kt1291.kt
T
Alexander Udalov 8b918ef1aa Add regression tests for obsolete issues
#KT-1291 Obsolete
 #KT-2895 Obsolete
 #KT-3060 Obsolete
 #KT-3298 Obsolete
 #KT-3613 Obsolete
 #KT-3862 Obsolete
2014-02-13 04:43:53 +04:00

28 lines
658 B
Kotlin

var result = 0
fun <T> Iterator<T>.foreach(action: (T) -> Unit) {
while (this.hasNext()) {
(action)(this.next())
}
}
fun <In, Out> Iterator<In>.select(f: (In) -> Out) : Iterator<Out> {
return Selector(this, f);
}
class Selector<In, Out>(val source: Iterator<In>, val f: (In) -> Out) : Iterator<Out> {
override fun hasNext(): Boolean = source.hasNext()
override fun next(): Out {
return (f)(source.next())
}
}
fun box(): String {
Array(4, { it + 1 }).iterator()
.select({i -> i * 10})
.foreach({k -> result += k})
if (result != 10+20+30+40) return "Fail: $result"
return "OK"
}