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