added a helper method for converting functions into iterators (which have all the various standard library APIs on them)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package iterators
|
||||
|
||||
import kotlin.*
|
||||
import kotlin.test.*
|
||||
import kotlin.util.*
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
class FunctionIteratorTest {
|
||||
|
||||
Test fun iterateOverFunction() {
|
||||
var count = 3
|
||||
|
||||
val iter = iterate<Int> {
|
||||
count--
|
||||
if (count >= 0) count else null
|
||||
}
|
||||
|
||||
val list = iter.toList()
|
||||
assertEquals(arrayList(2, 1, 0), list)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user