const DEFAULT_MAP_PARALLELISM = 10 ; param { Array | Iterable | Object } input param { AsyncFunction } iteratee export async function map < T , V > ( input , iteratee ) ; export async function map < T , V > ( input , iteratee ) ; export async function map < T extends Object , V > ( input , iteratee ) ; export async function map < T extends Object , V > ( input , iteratee ) ; export async function map ( input , iteratee ) { return mapLimit ( input , DEFAULT_MAP_PARALLELISM , iteratee ) ; } param { Array | Iterable | Object } input param { number } limit param { AsyncFunction } iteratee export async function mapLimit < T , V > ( input , limit , iteratee ) ; export async function mapLimit < T , V > ( input , limit , iteratee ) ; export async function mapLimit < T extends Object , V > ( input , limit , iteratee ) ; export async function mapLimit < T extends Object , V > ( input , limit , iteratee ) ; export async function mapLimit < V > ( input , limit , iteratee ) { if ( ! input ) { return [ ] ; } const isArray = Array . isArray ( input ) ; const size = ( ( ) => { if ( isArray ) { return input . length ; } let count = 0 ; for ( const __ in input ) { ++ count ; } return count ; } ) ( ) ; const allValues = new Array ( size ) ; const results = new Array ( size ) ; let i = 0 ; for ( const key in input ) { const possiblyNumericKey = isArray ? i : key ; allValues [ size - 1 - i ] = [ input [ key ] , i , possiblyNumericKey ] ; ++ i ; } const execute = async ( ) => { while ( allValues . length > 0 ) { const [ val , index , key ] = allValues . pop ( ) ; results [ index ] = await iteratee ( val , key ) ; } } ; const allExecutors = [ ] ; for ( let j = 0 ; j < limit ; ++ j ) { allExecutors . push ( execute ( ) ) ; } await Promise . all ( allExecutors ) ; return results ; } param { Array | Iterable | Object } input param { AsyncFunction } iteratee export async function mapSeries < T , V > ( input , iteratee ) ; export async function mapSeries < T , V > ( input , iteratee ) ; export async function mapSeries < T extends Object , V > ( input , iteratee ) ; export async function mapSeries < T extends Object , V > ( input , iteratee ) ; export async function mapSeries ( input , iteratee ) { return mapLimit ( input , 1 , iteratee ) ; } param { Array | Iterable | Object } input param { AsyncFunction } iteratee export async function flatMap < T , V > ( input , iteratee ) ; export async function flatMap < T , V > ( input , iteratee ) ; export async function flatMap < T extends Object , V > ( input , iteratee ) ; export async function flatMap < T extends Object , V > ( input , iteratee ) ; export async function flatMap ( input , iteratee ) { if ( ! input ) { return [ ] ; } const output = [ ] ; const nestedOutput = await map ( input , iteratee ) ; for ( const partialOutput of nestedOutput ) { if ( partialOutput && ( partialOutput as any ) . length !== undefined ) { output . push ( ... ( partialOutput as any ) ) ; } else { output . push ( partialOutput ) ; } } return output ; }