StopIteration = Error clone("StopIteration")

Iterator = Object clone() do(

    init = method(iterable,
        self iterable = iterable
        self i = -1
        self N = iterable __len__() - 1
    )

    __next__ = method(
        ((self i) < (self N)) ifTrue(
            self i = self i + 1
            self iterable __getitem__(self i)
        ) ifFalse(
            raise(StopIteration)
        )
    )

    repr = method(
        "Iterator({0})" format((self has("iterable") and (self iterable)) or "")
    )
)

List __iter__ = method(
    Iterator clone(self)
)

Range __iter__ = method(
    Iterator clone(self)
)
