Skip to content

Commit

Permalink
feat: has
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Jun 10, 2024
1 parent b8234cd commit 2e83122
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ fromIterable(new Set([1, 2, 3]))
```
</details>
<details>
<summary>has</summary>
```javascript
import { has } from '@ilteoood/re-flusso/has';

.pipeThrough(
has(new Set([1, 2, 3]))
)
```
</details>
<details>
<summary>last</summary>
Expand Down
6 changes: 3 additions & 3 deletions src/equals.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { filter } from "./filter";

export const equals = (
value: unknown,
export const equals = <T>(
value: T,
writableStrategy?: QueuingStrategy,
readableStrategy?: QueuingStrategy,
) => {
return filter(
(chunk: unknown) => chunk === value,
(chunk: T) => chunk === value,
writableStrategy,
readableStrategy,
);
Expand Down
13 changes: 13 additions & 0 deletions src/has.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { filter } from "./filter";

export const has = <T>(
values: Set<T>,
writableStrategy?: QueuingStrategy,
readableStrategy?: QueuingStrategy,
) => {
return filter(
(chunk: T) => values.has(chunk),
writableStrategy,
readableStrategy,
);
};
32 changes: 32 additions & 0 deletions test/has.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, expect, test } from "vitest";
import { fromIterable } from "../src/fromIterable";
import { fromRange } from "../src/numbers/fromRange";
import { pipeline } from "../src/pipeline";
import { toArray } from "../src/toArray";
import { has } from "../src/has";

describe("in", () => {
test("should work with empty list", async () => {
const destinationArray = [];

await pipeline(
fromIterable([]),
has(new Set([0, 1, 2])),
toArray(destinationArray),
);

expect(destinationArray).toEqual([]);
});

test("should correctly filter numbers", async () => {
const destinationArray = [];

await pipeline(
fromRange(1, 3),
has(new Set([0, 1, 2])),
toArray(destinationArray),
);

expect(destinationArray).toEqual([1, 2]);
});
});

0 comments on commit 2e83122

Please sign in to comment.