class_name PeekableIter extends Iterator

var _iter: Iterator
var _peeked: Variant

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

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

func peek() -> Option:
    if _peeked == null:
        _peeked = _iter.next()
    return _peeked

func next() -> Option:
    if _peeked == null:
        return _iter.next()
    else:
        var value = _peeked
        _peeked = null
        return value
