class_name Iterator extends RefCounted

func _to_string() -> String:
    return "Iterator"

func clone() -> Iterator:
    assert(false, "can't clone a abstract base class")
    return null

func next() -> Option:
    return Option.none

func collect() -> Array:
    var result = []
    for item in self:
        result.append(item)
    return result

func into_peekable() -> PeekableIter:
    return PeekableIter.new(self)

func into_indexed() -> IndexedIterator:
    return IndexedIterator.new(self)

func _iter_init(iter: Array) -> bool:
    return _iter_next(iter)

func _iter_next(iter: Array) -> bool:
    iter[0] = next()
    return iter[0].is_some()

func _iter_get(iter: Variant) -> Variant:
    return iter.unwrap()
