aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/SequenceUtil.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/util/SequenceUtil.kt')
-rw-r--r--src/main/kotlin/util/SequenceUtil.kt11
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)
+ }
+}