import { promiseAll } from "./promiseAll";

/**
 * A syntax sugar for Promise.all(arr.map(...)).
 */
export async function promiseAllMap<TElem, TRet>(
  arr: readonly TElem[] | Promise<readonly TElem[]>,
  func: (e: TElem, idx: number) => PromiseLike<TRet> | TRet,
): Promise<TRet[]> {
  return promiseAll((await arr).map((e, idx) => func(e, idx)));
}
