diff --git a/src/entrypoints/map.ts b/src/entrypoints/map.ts new file mode 100644 index 0000000..7936775 --- /dev/null +++ b/src/entrypoints/map.ts @@ -0,0 +1,16 @@ +type Mapper = (item: T, index: number, arrayLength: number) => R | Promise; + +export const map = async (data: Array, mapper: Mapper): Promise => { + const result: U[] = [] + let index = 0 + for (const item of data) { + result.push(await mapper(item, index, data.length)) + index++ + } + return result +} + +const double = (num: number) => num * 2 +const data = [1, 2, 3, 4, 5] + +map(data, double) \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 0786657..432a1f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export * from './entrypoints/retry' -export * from './entrypoints/sleep' \ No newline at end of file +export * from './entrypoints/sleep' +export * from './entrypoints/map'