Function flat

  • Flattens an input iterable up to a specified depth. Returns a new asynchronous iterable.

    Returns

    A function that accepts an input iterable and returns a new asynchronous iterable.

    Example

    const input = [1, [2, 3], [4, [5]]];
    const flatIterable = flat<number>(1)(input);

    (async () => {
    for await (const x of flatIterable) {
    console.log(x); // Logs 1, 2, 3, 4, [5]
    }
    })();

    Type Parameters

    • T

      The type of elements in the input iterable.

    • D extends number = 1

      The depth of flattening.

    Parameters

    • Optional depth: D

      The depth of flattening, defaults to 1.

    Returns ((input: AnyIterable<T>) => FlatAsyncIterable<T, D>)

Generated using TypeDoc