Type Alias SynchronousStreamOptions

SynchronousStreamOptions: {
    useIteratorHelpersIfAvailable: boolean;
}

Options to configure the stream, which are as follows:

  1. useIteratorHelpersIfAvailable, which allows iterator helpers (https://github.com/tc39/proposal-iterator-helpers) if they are available.

Type declaration

  • useIteratorHelpersIfAvailable: boolean

    If true, iterator helpers (i.e. map, filter, etc.) will be used if they are available. A full list can be found at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/drop. If false, the stream will use the default implementation, which will aggregate a list of operations for map, filter, etc. and apply them when iteration has begun. For operations such as drop, take, etc., the default implementation will return a new instance of the array stream, while the iterator helpers will modify the current iterator in place.

    Iterator helpers are more performant than the default implementation. However, iterator helpers cause recursion which cannot be resolved until the iterator is exhausted. This means that an array stream will reach a maximum recursion depth based on your browser, depending on the number of operations. For most browsers, this in the range of tens of thousands, but if you either have a low recursion depth ceiling or need to perform a large amount of operations, you may want to disable this option.

    Another reason to not use iterator helpers is they limit the ability to determine errors. With the default implementation, error handlers will be able to determine errors within the operation and examine the item before transformation by a map/filter/etc. operation. However, because iterator helpers do not have access to the base item before the operation, the error handler will be limited.

    The full proposal is available here, which, as of writing this, has been been approved but has not yet been incorporated in the ecmascript standard.

    Current support is widely available in Chrome, the latest in Firefox, Bun, Node and Deno, and not in Safari. More details on browser support can be found at caniuse.

    NOTE: This option only applies to synchronous streams. Asynchronous streams do not have any options to specify as of now, though there is a proposal for it.