@vgerbot/async
    Preparing search index...

    Function findIndex

    • Finds the index of the first item whose async predicate resolves to true. Returns -1 if no item matches.

      Type Parameters

      • I

        The input item type.

      Parameters

      • data: I[] | Promise<I[]>

        Input array, or a promise that resolves to one.

      • predicate: (item: I, token: CancellableToken) => Promise<boolean>

        Async predicate to evaluate.

      • Optionaloptions: FindIndexOptions

        Configuration options including cancellation and concurrency.

      Returns CancellableHandle<number>

      A cancellable handle resolving to the matched index or -1.

      const handle = findIndex(
      [1, 2, 3, 4],
      async (item, token) => {
      await token.sleep(10);
      return item > 2;
      },
      );

      const index = await handle; // 2
    • Finds the index of the first item whose async predicate resolves to true. Returns -1 if no item matches.

      Type Parameters

      • I

        The input item type.

      Parameters

      • data: CollectionInput<I> | Promise<CollectionInput<I>>

        Input array, or a promise that resolves to one.

      • predicate: (item: I, key: string | number, token: CancellableToken) => Promise<boolean>

        Async predicate to evaluate.

      • Optionaloptions: FindIndexOptions

        Configuration options including cancellation and concurrency.

      Returns CancellableHandle<number>

      A cancellable handle resolving to the matched index or -1.

      const handle = findIndex(
      [1, 2, 3, 4],
      async (item, token) => {
      await token.sleep(10);
      return item > 2;
      },
      );

      const index = await handle; // 2