aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/SequenceUtil.kt
blob: 2cb271d6221c04fa692108e87f0c236dfde9fb34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

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)
    }
}