Function spread

  • Spreads / expands iterable values.

    The source is expected to emit iterable values only, or else it will throw an error.

    import {pipe, spread} from 'iter-ops';

    const i = pipe(
    ['first', 'second'],
    spread()
    );

    console.log(...i); //=> 'f', 'i', 'r', 's', 't', 's', 'e', 'c', 'o', 'n', 'd'

    It implements the logic consistent with JavaScript's native spread operator, whereby it expands elements on the top level only, and it will throw an error when passed in a non-iterable value.

    If you want values expanded recursively, and without throwing errors, see operator flat.

    Type Parameters

    • T extends Iterable<unknown> | AsyncIterable<unknown>

    Returns Operation<T, T extends UnknownIterable<infer E>
        ? E
        : never>

    Throws

    TypeError: 'Value at index X is not iterable: ...' when a non-iterable value encountered.

    See