class_name DictionaryIterator extends Iterator

class Entry extends RefCounted:
    var key
    var value

    func _init(key: Variant, value: Variant) -> void:
        self.key = key
        self.value = value

var dict: Dictionary
var keys: Iterator

func _init(dict: Dictionary) -> void:
    self.dict = dict
    self.keys = ListIterator.from_array(dict.keys())

func next() -> Option:
    match keys.next():
        var _key when _key.is_some():
            var key = _key.unwrap()
            return Option.some(Entry.new(key, dict[key]))
    return Option.none
