type MapFunction = (input: In) => Promise<[In, Out] | null>; export async function map_parallel( inputs: Iterable, map_fn: MapFunction, ): Promise> { const queue = [...inputs].map((input) => map_fn(input)); return new Map( (await Promise.all(queue)).filter((job): job is [In, Out] => job !== null), ); }