class_name TakeWhileIter extends Iterator

var _iter: Iterator
var _predicate: Callable

func _init(iter: Iterator, predicate: Callable) -> void:
    _iter = iter
    _predicate = predicate

func clone() -> TakeWhileIter:
    return self

func next() -> Option:
    match _iter.next().filter(_predicate):
        var x when x.is_some(): return x
        _: return Option.none
