aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/SequenceUtil.kt
blob: b30744d77e5179216c3e28cfd70a73b801057463 (plain)
1
2
3
4
5
6
7
8
9
package moe.nea.firmament.util

fun <T : Any> T.iterate(iterator: (T) -> T?): Sequence<T> = sequence {
    var x: T? = this@iterate
    while (x != null) {
        yield(x)
        x = iterator(x)
    }
}