Skip to content

Commit d295b46

Browse files
committed
feat(asyncConcatMapOnce): add asyncConcatMapOnce function
1 parent 87452a1 commit d295b46

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
asyncAnyOnce,
77
asyncAppendOnce,
88
asyncAverageOnce,
9+
asyncConcatMapOnce,
910
asyncConcatOnce,
1011
asyncContainsOnce,
1112
asyncDropOnce,
@@ -571,3 +572,12 @@ test("asyncAppendOnce", async t => {
571572
[4, 5, 6]
572573
);
573574
});
575+
576+
test("asyncConcatMapOnce", async t => {
577+
t.deepEqual(
578+
await asyncToArrayOnce(
579+
asyncConcatMapOnce(asyncIterator(["1,2,3", "4,5,6"]), s => s.split(","))
580+
),
581+
["1", "2", "3", "4", "5", "6"]
582+
);
583+
});

index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,3 +1041,16 @@ export function asyncAppendOnce<T>(
10411041
): (a: AsyncIteratorLike<T>) => AsyncIterator<T> {
10421042
return a => asyncConcatOnce([a, b]);
10431043
}
1044+
1045+
export function asyncConcatMapOnce<T, U>(
1046+
iterator: AsyncIteratorLike<T>,
1047+
f: (element: T, index: number) => AsyncIteratorLike<U>
1048+
): AsyncIterator<U> {
1049+
return asyncConcatOnce(asyncMapOnce(iterator, f));
1050+
}
1051+
1052+
export function asyncConcatMapOnceFn<T, U>(
1053+
f: (element: T, index: number) => AsyncIteratorLike<U>
1054+
): (iterator: AsyncIteratorLike<T>) => AsyncIterator<U> {
1055+
return iterator => asyncConcatMapOnce(iterator, f);
1056+
}

0 commit comments

Comments
 (0)