Ion Fusion Documentation
Release 0.38a1-SNAPSHOT (2026-10-09T21:44:05.396Z)

Module /fusion/iterator

Stateful traversal of value sequences.

Fusion iterators are essentially identical to Java iterators, and their use is based on two procedures:

empty_iterator constant

An iterator with no elements. (iterator_has_next empty_iterator) always returns false, and (iterator_next empty_iterator) always throws an exception.

is_iterator procedure
(is_iterator value)

Checks if the value is an iterator. Returns true or false.

iterator_append procedure
(iterator_append iter1 iter2)

Returns an iterator that provides all the elements of iter1 and then all the elements of iter2.

iterator_choose procedure
(iterator_choose pred iter)

Returns an iterator whose elements are those provided by iter that satisfy predicate pred.

iterator_find procedure
(iterator_find pred iter)

Returns the first element of iter that satisfies predicate pred. If no element satisfies the predicate, the result is void.

iterator_has_next procedure
(iterator_has_next iterator)

Checks if the iterator will provide another value when iterator_next is called. Returns true or false.

After this procedure returns false for some iterator instance, all subsequent calls of iterator_has_next on the same instance are expected to return false, and all subsequent calls of iterator_next are expected to throw an exception.

iterator_map procedure
(iterator_map proc iter)

Returns an iterator whose elements are the results of applying proc to the corresponding elements of iter.

iterator_map_splicing procedure
(iterator_map_splicing proc iter)

Returns an iterator that applies an iterator-making proc to each element of iter, splicing the inner iterators into a single outer iterator.

iterator_next procedure
(iterator_next iterator)

Returns the next element of the iterator. When the iterator has no more elements, an exception is thrown.

list_from_iterator procedure
(list_from_iterator iterator)

Creates a stretchy list with the elements of iterator, in the same order.

At present, this procedure will fail if the iterator returns multiple results.

list_iterator procedure
(list_iterator list)

Returns an iterator over the elements of list.

make_iterator procedure
(make_iterator has_next_proc next_proc)

Returns an iterator that delegates iterator_has_next and iterator_next to the given procedures, which are usually closures with shared state.

sexp_iterator procedure
(sexp_iterator sexp)

Returns an iterator over the elements of sexp.

struct_iterator procedure
(struct_iterator struct)

Returns an iterator over the content of struct. Calls to iterator_next will return two results representing a single field: the field's name (as a symbol) and the field's value.

(define (show struct)
  (let [(iter (struct_iterator struct))]
    (let loop []
      (when (iterator_has_next iter)
        (let_values [((k v) (iterator_next iter))]
          (displayln k " --> " v)
          (loop))))))
(show {foo:"bar", hello:"goodbye", yes:false})

This code displays:

yes --> false
hello --> goodbye
foo --> bar
value_iterator procedure
(value_iterator value)

Returns an iterator that produces value as its only element.