baml.iter.Iterable

Implemented by types that can be iterated over.

Reference version

Signature

interface baml.iter.Iterable

Implemented by types that can be iterated over.

This is what for (x in xs) asks for: a container implements Iterable and hands out an iterator. It is Rust's IntoIterator, and plays the part of Python's __iter__ or JavaScript's [Symbol.iterator]. Because baml.iter.Iterator in turn requires Iterable, an iterator is itself iterable and can be passed anywhere an Iterable is wanted.

T[] and string implement it at the bottom of this file.

Source:<builtin>/baml/ns_iter/iter.bamlbytes 1154–2068

Associated types

type Item

type Error

= never

Required instance methods

function

iter

(
self
) -> baml.iter.Iterator<Error = (Self as baml.iter.Iterable).Error, Item = (Self as baml.iter.Iterable).Item> throws never

Creates an iterator over the value.

The return type is the interface rather than a concrete class, so the implementor picks its own iterator type: T[] returns a baml.iter.ArrayIterator, while every iterator in this file returns self.

That last part is worth remembering. Calling iter on something that is already an iterator hands back the same, shared iterator. It does not rewind a partly-consumed one, and two callers will pull from the same cursor.