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/__snapshots__/tuple_of_test.ts.snap b/is/__snapshots__/tuple_of_test.ts.snap index 2098ae2..ff7bd39 100644 --- a/is/__snapshots__/tuple_of_test.ts.snap +++ b/is/__snapshots__/tuple_of_test.ts.snap @@ -22,7 +22,7 @@ snapshot[`isTupleOf > returns properly named predicate function 3`] = ` ])" `; -snapshot[`isTupleOf > returns properly named predicate function 1`] = ` +snapshot[`isTupleOf > returns properly named predicate function 1`] = ` "isTupleOf([ isNumber, isString, @@ -30,9 +30,9 @@ snapshot[`isTupleOf > returns properly named predicate function 1`] = ` ], isArray)" `; -snapshot[`isTupleOf > returns properly named predicate function 2`] = `"isTupleOf([(anonymous)], isArrayOf(isString))"`; +snapshot[`isTupleOf > returns properly named predicate function 2`] = `"isTupleOf([(anonymous)], isArrayOf(isString))"`; -snapshot[`isTupleOf > returns properly named predicate function 3`] = ` +snapshot[`isTupleOf > returns properly named predicate function 3`] = ` "isTupleOf([ isTupleOf([ isTupleOf([ 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, diff --git a/is/tuple_of.ts b/is/tuple_of.ts index ac0d2f6..bed8c17 100644 --- a/is/tuple_of.ts +++ b/is/tuple_of.ts @@ -3,7 +3,7 @@ import type { Predicate, PredicateType } from "../type.ts"; import { isArray } from "./array.ts"; /** - * Return a type predicate function that returns `true` if the type of `x` is `TupleOf` or `TupleOf`. + * Return a type predicate function that returns `true` if the type of `x` is `TupleOf` or `TupleOf`. * * Use {@linkcode isUniformTupleOf} to check if the type of `x` is a tuple of uniform types. * @@ -19,7 +19,7 @@ import { isArray } from "./array.ts"; * } * ``` * - * With `predElse`: + * With `predRest` to represent rest elements: * * ```ts * import { is } from "@core/unknownutil"; @@ -56,20 +56,20 @@ export function isTupleOf< export function isTupleOf< T extends readonly [Predicate, ...Predicate[]], - E extends Predicate, + R extends Predicate, >( predTup: T, - predElse: E, -): Predicate<[...TupleOf, ...PredicateType]>; + predRest: R, +): Predicate<[...TupleOf, ...PredicateType]>; export function isTupleOf< T extends readonly [Predicate, ...Predicate[]], - E extends Predicate, + R extends Predicate, >( predTup: T, - predElse?: E, -): Predicate | [...TupleOf, ...PredicateType]> { - if (!predElse) { + predRest?: R, +): Predicate | [...TupleOf, ...PredicateType]> { + if (!predRest) { return rewriteName( (x: unknown): x is TupleOf => { if (!isArray(x) || x.length !== predTup.length) { @@ -82,17 +82,17 @@ export function isTupleOf< ); } else { return rewriteName( - (x: unknown): x is [...TupleOf, ...PredicateType] => { + (x: unknown): x is [...TupleOf, ...PredicateType] => { if (!isArray(x) || x.length < predTup.length) { return false; } 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); }, "isTupleOf", predTup, - predElse, + predRest, ); } } diff --git a/is/tuple_of_test.ts b/is/tuple_of_test.ts index c930390..e273efc 100644 --- a/is/tuple_of_test.ts +++ b/is/tuple_of_test.ts @@ -43,7 +43,7 @@ Deno.test("isTupleOf", async (t) => { }); }); -Deno.test("isTupleOf", async (t) => { +Deno.test("isTupleOf", async (t) => { await t.step("returns properly named predicate function", async (t) => { await assertSnapshot( t, @@ -67,27 +67,27 @@ Deno.test("isTupleOf", async (t) => { await t.step("returns true on T tuple", () => { const predTup = [is.Number, is.String, is.Boolean] as const; - const predElse = is.ArrayOf(is.Number); - assertEquals(isTupleOf(predTup, predElse)([0, "a", true, 0, 1, 2]), true); + const predRest = is.ArrayOf(is.Number); + assertEquals(isTupleOf(predTup, predRest)([0, "a", true, 0, 1, 2]), true); }); await t.step("returns false on non T tuple", () => { const predTup = [is.Number, is.String, is.Boolean] as const; - const predElse = is.ArrayOf(is.String); - assertEquals(isTupleOf(predTup, predElse)([0, 1, 2, 0, 1, 2]), false); - assertEquals(isTupleOf(predTup, predElse)([0, "a", 0, 1, 2]), false); + const predRest = is.ArrayOf(is.String); + assertEquals(isTupleOf(predTup, predRest)([0, 1, 2, 0, 1, 2]), false); + assertEquals(isTupleOf(predTup, predRest)([0, "a", 0, 1, 2]), false); assertEquals( - isTupleOf(predTup, predElse)([0, "a", true, 0, 0, 1, 2]), + isTupleOf(predTup, predRest)([0, "a", true, 0, 0, 1, 2]), false, ); - assertEquals(isTupleOf(predTup, predElse)([0, "a", true, 0, 1, 2]), false); + assertEquals(isTupleOf(predTup, predRest)([0, "a", true, 0, 1, 2]), false); }); await t.step("predicated type is correct", () => { const predTup = [is.Number, is.String, is.Boolean] as const; - const predElse = is.ArrayOf(is.Number); + const predRest = is.ArrayOf(is.Number); const a: unknown = [0, "a", true, 0, 1, 2]; - if (isTupleOf(predTup, predElse)(a)) { + if (isTupleOf(predTup, predRest)(a)) { assertType>( true, );