Function awaitedFilter

  • Performs [].filter() on an array but supports an async callback.

    Type Parameters

    • OriginalGeneric

    Parameters

    • arrayInput: readonly OriginalGeneric[]
    • filterCallback: (
          arrayElement: OriginalGeneric,
          index: number,
          wholeArray: readonly OriginalGeneric[],
      ) => Promise<unknown>
    • Optionaloptions: { blocking?: boolean }
      • Optionalblocking?: boolean

        Each call to the filter callback is blocking, meaning the next one won't start until the current one finishes. By default this is false.

    Returns Promise<OriginalGeneric[]>

    A new array (does not mutate).

    import {awaitedFilter} from '@augment-vir/common';

    const result = await awaitedFilter([1, 2, 3, 4, 5], async (value) => {
    return await Promise.resolve(value > 2);
    });