class_name FusedIterator extends Iterator

var _iters: Array[Iterator]
var _index: int = 0

func _init(iters: Array[Iterator]) -> void:
    _iters = iters

static func from(iterator: Variant) -> FusedIterator:
    var arr: Array[Iterator] = []
    for iter in iterator:
        arr.append(iter)
    return FusedIterator.new(arr)

func next() -> Option:
    if _index >= len(_iters): return Option.none

    match _iters[_index].next():
        var value when value.is_some():
            return value
        _:
            _index += 1
            return next()
