Function slice

  • Slices an input iterable between the specified start and end indices. If both start and end indices are non-negative, the slicing is performed lazily. Otherwise, the slicing is performed greedily.

    Returns

    A function that accepts an input iterable and returns an async iterable that yields the sliced values.

    Example

    const input = asyncIterable([1, 2, 3, 4, 5]);
    const sliced = slice(1, 4)(input);

    (async () => {
    for await (const value of sliced) {
    console.log(value); // Logs 2, 3, 4
    }
    })();

    Type Parameters

    • T

      The type of elements in the input iterable.

    Parameters

    • startIndex: number = 0

      Optional. The start index for the slice, defaults to 0.

    • endIndex: number = Number.POSITIVE_INFINITY

      Optional. The end index for the slice, defaults to Number.POSITIVE_INFINITY.

    Returns ((input: AnyIterable<T>) => AsyncIterable<Awaited<T>>)

      • (input: AnyIterable<T>): AsyncIterable<Awaited<T>>
      • Parameters

        Returns AsyncIterable<Awaited<T>>

Generated using TypeDoc