From d8acdb920ef64e4eb4edd8a072ae1dd17ae0dc33 Mon Sep 17 00:00:00 2001 From: Nicolas Lopes Date: Fri, 12 Jan 2024 18:53:36 -0300 Subject: [PATCH] export stuff --- src/entrypoints/map.ts | 16 ++++++++++++++++ src/index.ts | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/entrypoints/map.ts 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'