yta
    Preparing search index...

    Function slice

    • Slice the iterator between the indices. If either index is negative, count from the end. Works similar to Array.prototype.slice.

      For indices 0 ≤ startend this is the same as calling drop(start) and take(end - start) in sequence on an iterator.

      import { pipe } from "yta";
      import { asAsync, range } from "yta/sync";
      import { slice } from "yta/async";

      [...pipe(range(15), asAsync(), slice(10))];
      // => [10, 11, 12, 13, 14]

      [...pipe(range(15), asAsync(), slice(5, 8))];
      // => [5, 6, 7]

      [...pipe(range(15), slice(-5))];
      // => [10, 11, 12, 13, 14]

      [...pipe(range(15), slice(0, -5))];
      // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

      [...pipe(range(15), slice(5, -5))];
      // => [5, 6, 7, 8, 9]

      Note: Similar to drop and take—because the length of the iterator is not known—if you use negative index the entire iterator has to be consumed before yielding the first item. This can result in an infinite loop if the iterator is indefinite.

      See also:

      Type Parameters

      • A

      Parameters

      • start: number = 0
      • end: number = Number.POSITIVE_INFINITY

      Returns (items: Iterable<A>) => Generator<A, void>