CollectionHandlers: {
    at: ((expr: BoxedExpression, index: number | string) => undefined | BoxedExpression);
    indexOf: ((expr: BoxedExpression, target: BoxedExpression, from?: number) => number | string | undefined);
    iterator: ((expr: BoxedExpression, start?: number, count?: number) => Iterator<BoxedExpression, undefined>);
    keys: ((expr: BoxedExpression) => undefined | Iterator<string>);
    size: ((expr: BoxedExpression) => number);
}

The handlers are the primitive operations that can be performed on collections.

There are two types of collections:

  • finite collections, such as lists, tuples, sets, matrices, etc... The size() handler of finite collections returns the number of elements
  • infinite collections, such as sequences, ranges, etc... The size() handler of infinite collections returns Infinity Infinite collections are not indexable, they have no at() handler.

Type declaration

  • at: ((expr: BoxedExpression, index: number | string) => undefined | BoxedExpression)

    Return the element at the specified index. The first element is at(1), the last element is at(-1). If the index is <0, return the element at index size() + index + 1. The index can also be a string for example for dictionaries. If the index is invalid, return undefined.

  • indexOf: ((expr: BoxedExpression, target: BoxedExpression, from?: number) => number | string | undefined)

    Return the index of the first element that matches the target expression. The comparison is done using the target.isEqual() method. If the expression is not found, return undefined. If the expression is found, return the index, 1-based. If the expression is found multiple times, return the index of the first match.

    From is the starting index for the search. If negative, start from the end and search backwards.

      • (expr, target, from?): number | string | undefined
      • Parameters

        Returns number | string | undefined

  • iterator: ((expr: BoxedExpression, start?: number, count?: number) => Iterator<BoxedExpression, undefined>)

    Return an iterator

    • start is optional and is a 1-based index.
    • if start is not specified, start from index 1
    • count is optional and is the number of elements to return
    • if count is not specified or negative, return all the elements from start to the end

    If there is a keys() handler, there is no iterator() handler.

  • keys: ((expr: BoxedExpression) => undefined | Iterator<string>)

    If the collection is indexed by strings, return the valid values for the index.

  • size: ((expr: BoxedExpression) => number)

    Return the number of elements in the collection. An empty collection has a size of 0.