From da683ce0b7c7d60aefa2eef790e10061b772a3a2 Mon Sep 17 00:00:00 2001 From: hw Date: Fri, 10 May 2024 14:02:14 +0900 Subject: [PATCH] feat: expose public iterable properties --- src/Lazy/fx.ts | 8 ++++---- test/Lazy/fx.spec.ts | 18 +++++++++++++++++- type-check/Lazy/fx.test.ts | 5 +++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Lazy/fx.ts b/src/Lazy/fx.ts index bf3c3295..7ee8e164 100644 --- a/src/Lazy/fx.ts +++ b/src/Lazy/fx.ts @@ -36,8 +36,8 @@ class FxAsyncIterable { this.asyncIterable = asyncIterable; } - private [Symbol.asyncIterator]() { - return this.asyncIterable; + [Symbol.asyncIterator]() { + return this.asyncIterable[Symbol.asyncIterator](); } /** @@ -297,8 +297,8 @@ export class FxIterable { this.iterable = iterable; } - private [Symbol.iterator]() { - return this.iterable; + [Symbol.iterator]() { + return this.iterable[Symbol.iterator](); } /** diff --git a/test/Lazy/fx.spec.ts b/test/Lazy/fx.spec.ts index bc6174f1..45348c31 100644 --- a/test/Lazy/fx.spec.ts +++ b/test/Lazy/fx.spec.ts @@ -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) @@ -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) diff --git a/type-check/Lazy/fx.test.ts b/type-check/Lazy/fx.test.ts index ecbf9d1b..b572c1dc 100644 --- a/type-check/Lazy/fx.test.ts +++ b/type-check/Lazy/fx.test.ts @@ -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>, Test.Pass>(), check(), @@ -29,4 +32,6 @@ checks([ check, typeof res5>, Test.Pass>(), check, typeof res5>, Test.Pass>(), check, Test.Pass>(), + check(), + check(), ]);