@mirei/ts-collections
    Preparing search index...

    Function skipUntil

    • Skips elements until a type guard predicate returns true, then yields that element and the remainder, narrowing the element type.

      Type Parameters

      • TElement

        Type of elements within source.

      • TFiltered

        extends TElement Result type produced by predicate.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • predicate: IndexedTypePredicate<TElement, TFiltered>

        Type guard invoked for each element and its zero-based index; once it returns true, that element and all following elements are yielded.

      Returns IEnumerable<TFiltered>

      A deferred sequence starting with the first element that satisfies predicate.

      The predicate's index parameter increments for each inspected element until the condition is met.

      const mixed: (number | string)[] = ['a', 'b', 1, 2];
      const numbers = skipUntil(mixed, (x): x is number => typeof x === 'number').toArray();
      console.log(numbers); // [1, 2]
    • Skips elements until a predicate returns true, then yields that element and the remainder.

      Type Parameters

      • TElement

        Type of elements within source.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • predicate: IndexedPredicate<TElement>

        Predicate receiving the element and its zero-based index; once it returns true, enumeration stops skipping.

      Returns IEnumerable<TElement>

      A deferred sequence starting with the first element that satisfies predicate.

      The predicate runs until the first match is found; subsequent elements are yielded without further checks.

      const numbers = [0, 0, 1, 2, 3];
      const result = skipUntil(numbers, (_, i) => i >= 2).toArray();
      console.log(result); // [1, 2, 3]