Constructs an iterator over a collection.
The result depends on the type of arg
:
- For an iterator, that iterator is simply returned.
- For an array, returns an iterator over each of the array's elements.
- For a string, returns an iterator over each of the string's characters.
- For a table, returns an iterator which produces an array for each of the
table's entries, in an arbitrary order. Each array is newly-allocated and mutable,
and it contains two elements:
(key value)
. - For a coroutine, returns an iterator which produces each value yielded by the coroutine. The coroutine's final return value is not produced by the iterator.
Nothing prevents arg
from being mutated during iteration. This is memory-safe, but
it may cause the iterator to behave unpredictably.
When an iterator is passed to iter
, the result is an alias for arg
. Calling
iter-next!
for the result will also advance the original iterator.
To create a non-aliasing copy of an iterator, call clone
instead.