Skip to content

Commit b857747

Browse files
committed
feat(asyncRemoveOnce): add asyncRemoveOnce function
1 parent d3e04af commit b857747

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
asyncOnlyOnce,
2020
asyncPrefixMatchOnce,
2121
asyncPushOnce,
22+
asyncRemoveOnce,
2223
asyncSliceOnce,
2324
asyncTailOnce,
2425
asyncTakeOnce,
@@ -389,3 +390,10 @@ test("asyncExcludeFirstOnce", async t => {
389390
[1, 2, 4, 3, 2, 1]
390391
);
391392
});
393+
394+
test("asyncRemoveOnce", async t => {
395+
t.deepEqual(
396+
await asyncToArrayOnce(asyncRemoveOnce(asyncIterator([1, 2, 3, 4, 3, 2, 1]), 3)),
397+
[1, 2, 4, 2, 1]
398+
);
399+
});

index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,16 @@ export function asyncExcludeFirstOnceFn<T>(
598598
): (iterator: AsyncIteratorLike<T>) => AsyncIterator<T> {
599599
return iterator => asyncExcludeFirstOnce(iterator, predicate);
600600
}
601+
602+
export function asyncRemoveOnce<T>(
603+
iterator: AsyncIteratorLike<T>,
604+
value: T | Promise<T>
605+
): AsyncIterator<T> {
606+
return asyncExcludeOnce(iterator, async element => element === (await value));
607+
}
608+
609+
export function asyncRemoveOnceFn<T>(
610+
value: T | Promise<T>
611+
): (iterator: AsyncIteratorLike<T>) => AsyncIterator<T> {
612+
return iterator => asyncRemoveOnce(iterator, value);
613+
}

0 commit comments

Comments
 (0)