class_name IndexedIterator extends Iterator

class Indexed extends RefCounted:
    var value: Variant
    var index: int

    func _init(_value: Variant, _index: int) -> void:
        value = _value
        index = _index

var _iter: Iterator
var _index: int = 0

func _init(iter: Iterator) -> void:
    _iter = iter

func _add_index(value: Variant) -> Indexed:
    return Indexed.new(value, _index)

func clone() -> IndexedIterator:
    return IndexedIterator.new(_iter.clone())

func next() -> Option:
    return _iter.next().map(_add_index)
