ExtensionFunctionCalledFromFor

This commit is contained in:
develar
2012-06-22 17:17:52 +04:00
parent 2c3f3d2960
commit e83879e6f3
4 changed files with 43 additions and 6 deletions
@@ -0,0 +1,33 @@
package foo
class SimpleEnumerator {
private var counter = 0
fun getNext(): String {
counter++;
return counter.toString()
}
fun hasMoreElements(): Boolean = counter < 1
}
class SimpleEnumeratorWrapper(private val enumerator: SimpleEnumerator) {
val hasNext: Boolean
get() = enumerator.hasMoreElements()
fun next() = enumerator.getNext()
}
fun SimpleEnumerator.iterator(): SimpleEnumeratorWrapper {
return SimpleEnumeratorWrapper(this)
}
fun box(): Boolean {
var o = ""
val enumerator = SimpleEnumerator()
for (s in enumerator) {
o += s;
}
return o == "1"
}