Skip to content

Commit

Permalink
feat: expose public iterable properties (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppeeou authored May 13, 2024
1 parent 8a2bff9 commit 94ddf2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Lazy/fx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class FxAsyncIterable<A> {
this.asyncIterable = asyncIterable;
}

private [Symbol.asyncIterator]() {
return this.asyncIterable;
[Symbol.asyncIterator]() {
return this.asyncIterable[Symbol.asyncIterator]();
}

/**
Expand Down Expand Up @@ -297,8 +297,8 @@ export class FxIterable<A> {
this.iterable = iterable;
}

private [Symbol.iterator]() {
return this.iterable;
[Symbol.iterator]() {
return this.iterable[Symbol.iterator]();
}

/**
Expand Down
18 changes: 17 additions & 1 deletion test/Lazy/fx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { fx, toAsync } from "../../src";
import { fx, toArray, toAsync } from "../../src";

describe("fx", function () {
describe("sync", function () {
it("handle fx iterable (default)", function () {
const res1 = [...fx([1, 2, 3, 4, 5])];
expect(res1).toEqual([1, 2, 3, 4, 5]);

const res2 = [...fx("abc")];
expect(res2).toEqual(["a", "b", "c"]);
});

it("handle fx iterable", function () {
const res = fx([1, 2, 3, 4, 5])
.map((a) => a + 10)
Expand All @@ -11,6 +19,14 @@ describe("fx", function () {
});

describe("async", () => {
it("handle fx asyncIterable (default)", async function () {
const res1 = await toArray(fx(toAsync([1, 2, 3, 4, 5])));
expect(res1).toEqual([1, 2, 3, 4, 5]);

const res2 = await toArray(fx(toAsync("abc")));
expect(res2).toEqual(["a", "b", "c"]);
});

it("handle fx asyncIterable", async function () {
const res1 = await fx(toAsync([1, 2, 3, 4, 5]))
.map(async (a) => a + 10)
Expand Down
5 changes: 5 additions & 0 deletions type-check/Lazy/fx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const res7 = fx(toAsync([1, 2, 3]))
.map((a) => a)
.toArray();

const res8 = [...fx([1, 2, 3])];
const res9 = [...fx("abc")];

checks([
check<typeof res1, Cast<Iterable<number>, typeof res1>, Test.Pass>(),
check<typeof res2, number[], Test.Pass>(),
Expand All @@ -29,4 +32,6 @@ checks([
check<typeof res5, Cast<AsyncIterable<number>, typeof res5>, Test.Pass>(),
check<typeof res6, Cast<AsyncIterable<number>, typeof res5>, Test.Pass>(),
check<typeof res7, Promise<number[]>, Test.Pass>(),
check<typeof res8, number[], Test.Pass>(),
check<typeof res9, string[], Test.Pass>(),
]);

0 comments on commit 94ddf2a

Please sign in to comment.