diff --git a/src/Lazy/fx.ts b/src/Lazy/fx.ts index 646dd04c..bf3c3295 100644 --- a/src/Lazy/fx.ts +++ b/src/Lazy/fx.ts @@ -11,6 +11,7 @@ import join from "../join"; import reduce from "../reduce"; import some from "../some"; import type Cast from "../types/Cast"; +import type { DeepFlat } from "../types/DeepFlat"; import type IterableInfer from "../types/IterableInfer"; import type Key from "../types/Key"; import type { SyncReducer } from "../types/Reducer"; @@ -71,8 +72,10 @@ class FxAsyncIterable { * * see {@link https://fxts.dev/docs/flat | flat} */ - flat(depth?: number) { - return new FxAsyncIterable(flat(this.asyncIterable, depth)); + flat(depth?: T) { + return new FxAsyncIterable( + flat(this.asyncIterable, depth), + ) as FxAsyncIterable>; } /** @@ -326,8 +329,10 @@ export class FxIterable { * * see {@link https://fxts.dev/docs/flat | flat} */ - flat(depth?: number) { - return new FxIterable(flat(this.iterable, depth)); + flat(depth?: T) { + const res = flat(this.iterable, depth); + + return new FxIterable(res) as FxIterable>; } /** diff --git a/src/unicodeToArray.ts b/src/unicodeToArray.ts index 924c0e5f..9aaa2333 100644 --- a/src/unicodeToArray.ts +++ b/src/unicodeToArray.ts @@ -42,6 +42,7 @@ const rsSymbol = `(?:${[ ].join("|")})`; /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ +// eslint-disable-next-line no-misleading-character-class const reUnicode = RegExp(`${rsFitz}(?=${rsFitz})|${rsSymbol + rsSeq}`, "g"); /** diff --git a/type-check/Lazy/flat.test.ts b/type-check/Lazy/flat.test.ts index bc75cb7f..6de4b277 100644 --- a/type-check/Lazy/flat.test.ts +++ b/type-check/Lazy/flat.test.ts @@ -1,4 +1,4 @@ -import { flat, pipe, range, toAsync } from "../../src"; +import { flat, fx, pipe, range, toArray, toAsync } from "../../src"; import * as Test from "../../src/types/Test"; const { checks, check } = Test; @@ -29,6 +29,33 @@ const res16 = flat( })(), ); +const res17 = fx([1, 2]).flat().toArray(); +// prettier-ignore +const res18 = fx([1, [2]]).flat().toArray(); +// prettier-ignore +const res19 = fx([1, [2, [3]]]).flat().toArray(); +// prettier-ignore +const res20 = fx([1, [2, [3]]]).flat(2).toArray(); + +const res21 = fx(["a", "b"]).flat().toArray(); +// prettier-ignore +const res22 = fx(['a', ['b']]).flat().toArray(); +// prettier-ignore +const res23 = fx(['a', ['b', ['c']]]).flat().toArray(); +// prettier-ignore +const res24 = fx(['a', ['b', ['c']]]).flat(2).toArray(); + +// prettier-ignore +const res25 = fx(['a', 'b']).toAsync().flat().toArray(); +// prettier-ignore +const res26 = fx(['a', ['b']]).toAsync().flat().toArray(); + +// prettier-ignore +const res27 = fx(['a', ['b', ['c']]]).toAsync().flat().toArray(); +const res28 = pipe(["a", ["b", ["c"]]], toAsync, flat, toArray); +// prettier-ignore +const res29 = fx(['a', ['b', ['c']]]).toAsync().flat(2).toArray(); + checks([ check, Test.Pass>(), check, Test.Pass>(), @@ -49,4 +76,20 @@ checks([ check, Test.Pass>(), check, Test.Pass>(), // prettier-ignore check>, Test.Pass>(), // prettier-ignore + + check(), + check(), + check(), + check(), + + check(), + check(), + check(), + check(), + + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), + check, Test.Pass>(), ]); diff --git a/type-check/pipe.test.ts b/type-check/pipe.test.ts index 0b123656..a319bf3c 100644 --- a/type-check/pipe.test.ts +++ b/type-check/pipe.test.ts @@ -138,9 +138,11 @@ const Code = { } as const; type Code = (typeof Code)[keyof typeof Code]; +// eslint-disable-next-line @typescript-eslint/no-unused-vars const res18 = pipe({ code: Code.None }, (_: { code: Code }): Code => Code.None); const res19 = pipe( { code: Code.None }, + // eslint-disable-next-line @typescript-eslint/no-unused-vars async (_: { code: Code }): Promise => Code.None, );