@vgerbot/async
    Preparing search index...

    Function partition

    • Splits a collection into two arrays based on an async predicate. Returns a tuple [truthy[], falsy[]] where truthy contains items that passed the predicate and falsy contains items that failed.

      Type Parameters

      • I

        The input item type.

      Parameters

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

        Input collection, or a promise that resolves to one.

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

        Async predicate to evaluate each item.

      • Optionaloptions: PartitionOptions<I>

        Configuration options including cancellation and concurrency.

      Returns CancellableHandle<[I[], I[]]>

      A cancellable handle resolving to [truthy[], falsy[]].

      const handle = partition(
      [1, 2, 3, 4, 5],
      async (item) => item % 2 === 0,
      );

      const [evens, odds] = await handle; // [[2, 4], [1, 3, 5]]
    • Splits a collection into two arrays based on an async predicate. Returns a tuple [truthy[], falsy[]] where truthy contains items that passed the predicate and falsy contains items that failed.

      Type Parameters

      • I

        The input item type.

      Parameters

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

        Input collection, or a promise that resolves to one.

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

        Async predicate to evaluate each item.

      • Optionaloptions: PartitionOptions<I>

        Configuration options including cancellation and concurrency.

      Returns CancellableHandle<[I[], I[]]>

      A cancellable handle resolving to [truthy[], falsy[]].

      const handle = partition(
      [1, 2, 3, 4, 5],
      async (item) => item % 2 === 0,
      );

      const [evens, odds] = await handle; // [[2, 4], [1, 3, 5]]