Skip to content

Commit a9386a7

Browse files
committed
feat(asyncExcludeNullOnce): add asyncExcludeNullOnce function
1 parent aec9537 commit a9386a7

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
asyncDropWhileOnce,
77
asyncEmptyOnce,
88
asyncEqualOnce,
9+
asyncExcludeNullOnce,
910
asyncExcludeOnce,
1011
asyncFilterOnce,
1112
asyncInitialOnce,
@@ -371,3 +372,10 @@ test("asyncExcludeOnce", async t => {
371372
[3, 4, 3]
372373
);
373374
});
375+
376+
test("asyncExcludeNullOnce", async t => {
377+
t.deepEqual(await asyncToArrayOnce(asyncExcludeNullOnce(asyncIterator(["a", null, "b"]))), [
378+
"a",
379+
"b"
380+
]);
381+
});

index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {equal as defaultEqual} from "@softwareventures/ordered";
22
import type {AsyncIterableLike} from "@softwareventures/async-iterable";
33
import {hasProperty} from "unknown";
44
import {asyncIterable} from "@softwareventures/async-iterable";
5+
import {isNotNull} from "@softwareventures/nullable";
56

67
export type AsyncIteratorLike<T> =
78
| AsyncIterator<T>
@@ -566,3 +567,9 @@ export function asyncExcludeOnceFn<T>(
566567
): (iterator: AsyncIteratorLike<T>) => AsyncIterator<T> {
567568
return iterator => asyncExcludeOnce(iterator, predicate);
568569
}
570+
571+
export function asyncExcludeNullOnce<T>(
572+
iterator: AsyncIteratorLike<T | null | undefined>
573+
): AsyncIterator<T> {
574+
return asyncFilterOnce(iterator, isNotNull);
575+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"dependencies": {
2525
"@softwareventures/async-iterable": "^1.0.1",
26+
"@softwareventures/nullable": "^3.0.0",
2627
"@softwareventures/ordered": "^2.0.0",
2728
"tslib": "2.4.0",
2829
"unknown": "^0.2.5"

yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ __metadata:
854854
"@commitlint/cz-commitlint": 17.1.2
855855
"@softwareventures/async-iterable": ^1.0.1
856856
"@softwareventures/eslint-config": 7.0.0
857+
"@softwareventures/nullable": ^3.0.0
857858
"@softwareventures/ordered": ^2.0.0
858859
"@softwareventures/precise-commits": 2.0.22
859860
"@softwareventures/prettier-config": 3.0.0
@@ -910,7 +911,7 @@ __metadata:
910911
languageName: node
911912
linkType: hard
912913

913-
"@softwareventures/nullable@npm:^2.0.0 || ^3.0.0":
914+
"@softwareventures/nullable@npm:^2.0.0 || ^3.0.0, @softwareventures/nullable@npm:^3.0.0":
914915
version: 3.0.0
915916
resolution: "@softwareventures/nullable@npm:3.0.0"
916917
dependencies:

0 commit comments

Comments
 (0)