Skip to content

Commit 7078bf2

Browse files
committed
feat(asyncPrependOnce): add asyncPrependOnce function
1 parent 8e8c097 commit 7078bf2

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

index.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
asyncOnlyOnce,
3636
asyncOrOnce,
3737
asyncPrefixMatchOnce,
38+
asyncPrependOnce,
3839
asyncPushOnce,
3940
asyncRemoveFirstOnce,
4041
asyncRemoveOnce,
@@ -533,3 +534,22 @@ test("asyncConcatOnce", async t => {
533534
[]
534535
);
535536
});
537+
538+
test("asyncPrependOnce", async t => {
539+
t.deepEqual(
540+
await asyncToArrayOnce(
541+
asyncPrependOnce(asyncIterator([1, 2, 3]))(asyncIterator([4, 5, 6]))
542+
),
543+
[1, 2, 3, 4, 5, 6]
544+
);
545+
t.deepEqual(
546+
await asyncToArrayOnce(
547+
asyncPrependOnce(asyncIterator<number>([]))(asyncIterator([4, 5, 6]))
548+
),
549+
[4, 5, 6]
550+
);
551+
t.deepEqual(
552+
await asyncToArrayOnce(asyncPrependOnce(asyncIterator([1, 2, 3]))(asyncIterator([]))),
553+
[1, 2, 3]
554+
);
555+
});

index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,3 +1029,9 @@ export function asyncConcatOnce<T>(
10291029
let next = first;
10301030
return {next: async () => next()};
10311031
}
1032+
1033+
export function asyncPrependOnce<T>(
1034+
a: AsyncIteratorLike<T>
1035+
): (b: AsyncIteratorLike<T>) => AsyncIterator<T> {
1036+
return b => asyncConcatOnce([a, b]);
1037+
}

0 commit comments

Comments
 (0)