Skip to main content

spread_array

Function spread_array 

Source
pub fn spread_array<A: IVm>(
    items: impl IntoIterator<Item = ArrayItem<A>>,
) -> Result<Any<A>, Any<A>>
Expand description

The array an item list holds, a spread among them: each value an element, and each spread every value its operand iterates, in order. A spread of a value that is not iterable throws, so the array is an operation’s Result where an array without a spread is a value.

Every spread’s iterator is already established by spread_item, and the array’s length is bounded before anything is built: past JavaScript’s limit, 2³² − 1 elements and Array<A>‘s u32 length, the result is the RangeError ArrayCreate throws, refused on the iterators’ lower bounds — exact for an array — and, since a string’s code points are only known by walking it, checked again as each element is added, so the build never passes the limit. Delaying the iteration is unobservable: neither an array nor a string runs code or throws while iterated. The elements’ room is reserved up front and before every growth, so a length under the limit whose elements the machine cannot hold is the same RangeError, not an abort. The array built from them is the container constructor’s own allocation, which is not fallible yet (todo/131-non-panicking-allocator.md): a machine that can hold the elements but not a second copy of them still aborts.