diff options
Diffstat (limited to 'src/main/kotlin/util/SequenceUtil.kt')
-rw-r--r-- | src/main/kotlin/util/SequenceUtil.kt | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/main/kotlin/util/SequenceUtil.kt b/src/main/kotlin/util/SequenceUtil.kt new file mode 100644 index 0000000..7b5bad0 --- /dev/null +++ b/src/main/kotlin/util/SequenceUtil.kt @@ -0,0 +1,11 @@ + + +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) + } +} |