Created
June 19, 2017 13:36
-
-
Save ezura/ddb876f11cba2749467b5011744b5d5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A : Iterable<String> { | |
| override operator fun iterator(): Iterator<String> = MyIterator() | |
| } | |
| class MyIterator: Iterator<String> { | |
| override operator fun hasNext(): Boolean = Math.random() < 0.5 | |
| override operator fun next(): String = "a" | |
| } | |
| // A().forEach({ print(it)}) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for in だけなら、Iterable、Iterator への準拠を宣言しなくてもできる