Iterable

public protocol Iterable

A type that can hand out an iterator over its contents — what for-in loops desugar through, and what most collections conform to.

Iterable is one level above Iterator: a collection conforms to Iterable and produces a fresh Iter each call to iter(), leaving the source intact. (Compare with Iterator, which is consumed in place.) Every Iterator is also Iterable via the blanket conformance below — iter() on an iterator returns itself.

Examples

for item in myCollection { // identical to: // var it = myCollection.iter(); // while let .Some(item) = it.next() { ... } }

Associated Types

type Item

The element type that iteration yields.

type TargetIterator

The concrete iterator type returned by iter(). Constrained so TargetIterator.Item matches Self.Item.

Methods

func iter() -> TargetIterator

Builds a fresh iterator over the contents.

Defined in lang/std/iter/iterator.ks