import type { A } from 'ts-toolbelt' ; import type { L } from 'ts-toolbelt' ; import type { O } from 'ts-toolbelt' ; export type LMapper < I , R > = ( item : I , key : number ) => R ; export type OMapper < I , R > = ( item : I , key : string ) => R ; type Map < A , R > = { [ K in keyof A ] : R ; } ; function mapList < L extends L . List , I , R > ( object , mapper ) { const mapped = new Array ( object . length ) ; for ( let i = 0 ; i < object . length ; ++ i ) { mapped [ i ] = mapper ( object [ i ] , i ) ; } return mapped as any ; } function mapObject < O extends object , I , R > ( object , mapper ) { const mapped = { } ; const keys = Object . keys ( object ) ; for ( let i = 0 ; i < keys . length ; ++ i ) { mapped [ i ] = mapper ( object [ keys [ i ] ] , keys [ i ] ) ; } return mapped as any ; } param object param mapper returns const map = ( ( object , mapper ) => { return Array . isArray ( object ) ? mapList ( object , mapper ) : mapObject ( object , mapper ) ; } ) as any ; export { map } ;