diff --git a/is/__snapshots__/parameters_of_test.ts.snap b/is/__snapshots__/parameters_of_test.ts.snap index d1de1ce..f37c835 100644 --- a/is/__snapshots__/parameters_of_test.ts.snap +++ b/is/__snapshots__/parameters_of_test.ts.snap @@ -24,7 +24,7 @@ snapshot[`isParametersOf > returns properly named predicate function 4`] = ` ])" `; -snapshot[`isParametersOf > returns properly named predicate function 1`] = ` +snapshot[`isParametersOf > returns properly named predicate function 1`] = ` "isParametersOf([ isNumber, isString, @@ -32,11 +32,11 @@ snapshot[`isParametersOf > returns properly named predicate function 1`] = ], isArray)" `; -snapshot[`isParametersOf > returns properly named predicate function 2`] = `"isParametersOf([(anonymous)], isArrayOf(isString))"`; +snapshot[`isParametersOf > returns properly named predicate function 2`] = `"isParametersOf([(anonymous)], isArrayOf(isString))"`; -snapshot[`isParametersOf > returns properly named predicate function 3`] = `"isParametersOf([], isArrayOf(isString))"`; +snapshot[`isParametersOf > returns properly named predicate function 3`] = `"isParametersOf([], isArrayOf(isString))"`; -snapshot[`isParametersOf > returns properly named predicate function 4`] = ` +snapshot[`isParametersOf > returns properly named predicate function 4`] = ` "isParametersOf([ isParametersOf([ isParametersOf([ diff --git a/is/parameters_of.ts b/is/parameters_of.ts index 819d95c..a202ca7 100644 --- a/is/parameters_of.ts +++ b/is/parameters_of.ts @@ -28,7 +28,7 @@ import { isArray } from "./array.ts"; * } * ``` * - * With `predElse`: + * With `predRest` to represent rest parameters: * * ```ts * import { as, is } from "@core/unknownutil"; @@ -71,18 +71,18 @@ export function isParametersOf< E extends Predicate, >( predTup: T, - predElse: E, + predRest: E, ): Predicate<[...ParametersOf, ...PredicateType]>; export function isParametersOf< T extends readonly [...Predicate[]], E extends Predicate, >( predTup: T, - predElse?: E, + predRest?: E, ): Predicate | [...ParametersOf, ...PredicateType]> { const requiresLength = 1 + predTup.findLastIndex((pred) => !hasOptional(pred)); - if (!predElse) { + if (!predRest) { return rewriteName( (x: unknown): x is ParametersOf => { if ( @@ -103,11 +103,11 @@ export function isParametersOf< } const head = x.slice(0, predTup.length); const tail = x.slice(predTup.length); - return predTup.every((pred, i) => pred(head[i])) && predElse(tail); + return predTup.every((pred, i) => pred(head[i])) && predRest(tail); }, "isParametersOf", predTup, - predElse, + predRest, ); } } diff --git a/is/parameters_of_test.ts b/is/parameters_of_test.ts index 6bae4b2..478d806 100644 --- a/is/parameters_of_test.ts +++ b/is/parameters_of_test.ts @@ -59,7 +59,7 @@ Deno.test("isParametersOf", async (t) => { }); }); -Deno.test("isParametersOf", async (t) => { +Deno.test("isParametersOf", async (t) => { await t.step("returns properly named predicate function", async (t) => { assertEquals(typeof isParametersOf([], is.Array), "function"); await assertSnapshot( @@ -92,32 +92,32 @@ Deno.test("isParametersOf", async (t) => { await t.step("returns true on T tuple", () => { const predTup = [is.Number, is.String, as.Optional(is.Boolean)] as const; - const predElse = is.ArrayOf(is.Number); + const predRest = is.ArrayOf(is.Number); assertEquals( - isParametersOf(predTup, predElse)([0, "a", true, 0, 1, 2]), + isParametersOf(predTup, predRest)([0, "a", true, 0, 1, 2]), true, ); assertEquals( - isParametersOf(predTup, predElse)([0, "a", undefined, 0, 1, 2]), + isParametersOf(predTup, predRest)([0, "a", undefined, 0, 1, 2]), true, ); - assertEquals(isParametersOf(predTup, predElse)([0, "a"]), true); + assertEquals(isParametersOf(predTup, predRest)([0, "a"]), true); }); await t.step("returns false on non T tuple", () => { const predTup = [is.Number, is.String, as.Optional(is.Boolean)] as const; - const predElse = is.ArrayOf(is.String); - assertEquals(isParametersOf(predTup, predElse)([0, 1, 2, 0, 1, 2]), false); - assertEquals(isParametersOf(predTup, predElse)([0, "a", 0, 1, 2]), false); + const predRest = is.ArrayOf(is.String); + assertEquals(isParametersOf(predTup, predRest)([0, 1, 2, 0, 1, 2]), false); + assertEquals(isParametersOf(predTup, predRest)([0, "a", 0, 1, 2]), false); assertEquals( - isParametersOf(predTup, predElse)([0, "a", true, 0, 1, 2]), + isParametersOf(predTup, predRest)([0, "a", true, 0, 1, 2]), false, ); assertEquals( - isParametersOf(predTup, predElse)([0, "a", undefined, 0, 1, 2]), + isParametersOf(predTup, predRest)([0, "a", undefined, 0, 1, 2]), false, ); - assertEquals(isParametersOf(predTup, predElse)([0, "a", "b"]), false); + assertEquals(isParametersOf(predTup, predRest)([0, "a", "b"]), false); }); await t.step("predicated type is correct", () => { @@ -127,9 +127,9 @@ Deno.test("isParametersOf", async (t) => { as.Optional(is.String), as.Optional(is.Boolean), ] as const; - const predElse = is.ArrayOf(is.Number); + const predRest = is.ArrayOf(is.Number); const a: unknown = [0, "a"]; - if (isParametersOf(predTup, predElse)(a)) { + if (isParametersOf(predTup, predRest)(a)) { assertType< Equal< typeof a,