Skip to content

Commit 617d3b8

Browse files
committed
feat(asyncAndOnce): add asyncAndOnce function
1 parent 5198d8b commit 617d3b8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

index.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {ExecutionContext} from "ava";
22
import test from "ava";
33
import {
4+
asyncAndOnce,
45
asyncAverageOnce,
56
asyncContainsOnce,
67
asyncDropOnce,
@@ -484,3 +485,9 @@ test("asyncAverageOnce", async t => {
484485
t.is(await asyncAverageOnce(asyncIterator([1, 2, 3, 2])), 2);
485486
t.is(await asyncAverageOnce(asyncIterator([])), null);
486487
});
488+
489+
test("asyncAndOnce", async t => {
490+
t.true(await asyncAndOnce(asyncIterator([true, true, true])));
491+
t.false(await asyncAndOnce(asyncIterator([true, false, true])));
492+
t.true(await asyncAndOnce(asyncIterator([])));
493+
});

index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,3 +954,7 @@ export async function asyncAverageOnce(
954954
);
955955
return count === 0 ? null : sum / count;
956956
}
957+
958+
export async function asyncAndOnce(iterator: AsyncIteratorLike<boolean>): Promise<boolean> {
959+
return (await asyncFindIndexOnce(iterator, element => !element)) == null;
960+
}

0 commit comments

Comments
 (0)