## std/iterators: The Iter interface and associated functions. ## This module is imported by default. ## The Iter interface. Any type implementing `next()` is iterable. pub type Iter[T] = interface next(mut Self): Option[T] # todo: useful functions for an iterator # https://doc.rust-lang.org/std/iter/trait.Iterator.html#provided-methods pub func advance_by[T](self: Iter[T], n: uint): Result[T, ...] = for i in 0 .. n: if self.next().is_none(): return Error(...) Okay pub func get[T](self: Iter[T], at: uint): Option[T] self.advance_by(at-1).ok? self.next() # todo: implement iter[T](self: ...): Iter[T] funcs # todo: efficient functional methods ## The Peek interface. Any type implementing `Iter`, `peek`, and `peek_nth` is peekable. pub type Peek[T] = interface next(mut Self): Option[T] peek(mut Self): Option[T] peek_nth(mut Self, int): Option[T] # todo: implement peek[T](self: Iter[T]): Peek[T] # todo: implement Peekable struct # https://github.com/LukeMathWalker/multipeek/blob/main/src/lib.rs ## We don't want a Countable. It's not terribly useful. # pub type Countable[T] = interface # next(mut Self): Option[T] # len(Self): uint # get(Self, uint): Option[T]