Documentation
    Preparing search index...
    • Transforms each element of an array using an asynchronous function to create a new array.

      Similar to JavaScript's native map but processes asynchronous functions sequentially. Each element's transformation is completed before proceeding to the next element, ensuring order is maintained. This function still maintains the currying pattern for composition.

      Type Parameters

      • Input

        The type of elements in the input array

      • Output

      Parameters

      • elements: readonly Input[]

        The readonly array to transform

      • closure: (elem: Input, index: number, array: readonly Input[]) => Promise<Output>

      Returns Promise<Output[]>

      A function that takes a transformation function and returns a Promise resolving to the transformed array

        const userIds = [1, 2, 3, 4, 5];

      const userDetails = await ArrayUtil.asyncMap(userIds)(
      async (id, index) => {
      console.log(`Fetching user ${id} (${index + 1}/${userIds.length})`);
      const response = await fetch(`/api/users/${id}`);
      return await response.json();
      }
      );
      console.log('All users fetched:', userDetails);