Iterator

protocol Iterator

A stateful, single-pass source of values.

next mutates traversal state and returns none permanently after exhaustion. Iterator adapters consume their source, unlike Iterable, which borrows a reusable collection to create a fresh iterator.

Methods

mut func next() -> Element?

Advances once, yielding the next element or permanent exhaustion.

View Source
mut func next() -> Element?

consuming func iter() -> Self

Treats this iterator as its own iteration source.

View Source
consuming func iter() -> Self { self }

consuming func into_iter() -> Self

Consumes this value and returns an iterator over its elements.

View Source
consuming func into_iter() -> Self { self }

consuming func map<U>(consume fn: (Self.Element) -> U) -> Map<Self, U>

Returns a lazy adapter that applies fn as each source element is requested.

The source iterator and callback are consumed into the adapter; no element is read and no callback is invoked until next.

View Source
consuming func map<U>(consume fn: (Self.Element) -> U) -> Map<Self, U> {
	Map(inner: self, map: fn)
}

consuming func peekable() -> Peek<Self>

Wraps this iterator with one-element lookahead.

View Source
consuming func peekable() -> Peek<Self> {
	Peek(inner: self)
}

consuming func skip(count: Int) -> Self

Eagerly consumes and discards up to count elements, then returns the iterator.

Counts at or below zero leave the iterator unchanged. Exhaustion before the requested count is not an error; the returned iterator remains exhausted.

View Source
consuming func skip(count: Int) -> Self {
	let i = 0
	loop i < count {
		self.next()
		i = i + 1
	}
	self
}

mut func swap(i: Int, j: Int)

Optional in-place reordering hook; the default iterator has nothing to swap.

View Source
mut func swap(i: Int, j: Int) {}