core: Merge all ways of calling function into a single Call function

This commit is contained in:
gvergnaud
2023-04-15 12:24:35 +02:00
parent 714599186f
commit ff51010d7b
22 changed files with 355 additions and 447 deletions

View File

@@ -37,12 +37,12 @@ type res1 = Pipe<
// ^? 62
[1, 2, 3, 4],
[
Tuples.Map<Numbers.Add<3>>, // [4, 5, 6, 7]
Tuples.Join<".">, // "4.5.6.7"
Strings.Split<".">, // ["4", "5", "6", "7"]
Tuples.Map<Strings.Prepend<"1">>, // ["14", "15", "16", "17"]
Tuples.Map<Strings.ToNumber>, // [14, 15, 16, 17]
Tuples.Sum // 62
Tuples.Map<Numbers.Add<3>>, // [4, 5, 6, 7]
Tuples.Join<".">, // "4.5.6.7"
Strings.Split<".">, // ["4", "5", "6", "7"]
Tuples.Map<Strings.Prepend<"1">>, // ["14", "15", "16", "17"]
Tuples.Map<Strings.ToNumber>, // [14, 15, 16, 17]
Tuples.Sum // 62
]
>;
```

View File

@@ -10,8 +10,6 @@ sidebar_position: 0
## `PipeRight`
## `Call`
## `Apply`
## `Eval`
## `Call`

View File

@@ -1,11 +1,6 @@
import {
Apply,
Call,
Call2,
Call3,
Call4,
Call5,
Eval,
Fn,
Pipe,
PipeRight,
@@ -43,17 +38,13 @@ export {
Pipe,
PipeRight,
Call,
Call2,
Call3,
Call4,
Call5,
Call as $,
Apply,
Compose,
ComposeLeft,
Constant,
Identity,
PartialApply,
Apply,
Eval,
Match,
Booleans,
Objects,

View File

@@ -1,4 +1,4 @@
import { MergeArgs } from "./impl/MergeArgs";
import { ExcludePlaceholders, MergeArgs } from "./impl/MergeArgs";
import { Head } from "../helpers";
declare const rawArgs: unique symbol;
@@ -69,99 +69,35 @@ export type Apply<fn extends Fn, args extends unknown[]> = (fn & {
})["return"];
/**
* Call a HOTScript function with the only one argument.
* Calls a HOTScript function.
*
* @param fn - The function to call.
* @param arg1 - The argument to pass to the function.
* @returns The result of the function.
* @param ...args - optional arguments
*
* @example
* ```ts
* type T0 = Call<Numbers.Negate, 1>; // -1
* type T0 = Call<Numbers.Add<1, 2>>; // 3
* type T1 = Call<Numbers.Add<1>, 2>; // 3
* type T2 = Call<Numbers.Add, 1, 2>; // 3
* type T3 = Call<
* Tuples.Map<Strings.Split<".">, ["a.b", "b.c"]>
* >; // [["a", "b"], ["b", "c"]]
* ```
*/
export type Call<fn extends Fn, arg1> = (fn & {
[rawArgs]: [arg1];
})["return"];
/**
* Call a HOTScript function like a normal Utility type.
*
* @param fn - The function to call.
*
* @example
* ```ts
* type T0 = Eval<Numbers.Add<1, 2>>; // 3
* type T1 = Eval<Numbers.Negate<1>>; // -1
* ```
*/
export type Eval<fn extends Fn> = (fn & {
[rawArgs]: [];
})["return"];
/**
* Call a HOTScript function with the two arguments.
*
* @param fn - The function to call.
* @param arg1 - The first argument to pass to the function.
* @param arg2 - The second argument to pass to the function.
* @returns The result of the function.
*
* @example
* ```ts
* type T0 = Call2<Numbers.Add, 1, 2>; // 3
* ```
*/
export type Call2<fn extends Fn, arg1, arg2> = (fn & {
[rawArgs]: [arg1, arg2];
})["return"];
/**
* Call a HOTScript function with the three arguments.
*
* @param fn - The function to call.
* @param arg1 - The first argument to pass to the function.
* @param arg2 - The second argument to pass to the function.
* @param arg3 - The third argument to pass to the function.
* @returns The result of the function.
*/
export type Call3<fn extends Fn, arg1, arg2, arg3> = (fn & {
[rawArgs]: [arg1, arg2, arg3];
})["return"];
/**
* Call a HOTScript function with the four arguments.
*
* @param fn - The function to call.
* @param arg1 - The first argument to pass to the function.
* @param arg2 - The second argument to pass to the function.
* @param arg3 - The third argument to pass to the function.
* @param arg4 - The fourth argument to pass to the function.
* @returns The result of the function.
*/
export type Call4<fn extends Fn, arg1, arg2, arg3, arg4> = (fn & {
[rawArgs]: [arg1, arg2, arg3, arg4];
})["return"];
/**
* Call a HOTScript function with the five arguments.
*
* @param fn - The function to call.
* @param arg1 - The first argument to pass to the function.
* @param arg2 - The second argument to pass to the function.
* @param arg3 - The third argument to pass to the function.
* @param arg4 - The fourth argument to pass to the function.
* @param arg5 - The fifth argument to pass to the function.
* @returns The result of the function.
*/
export type Call5<fn extends Fn, arg1, arg2, arg3, arg4, arg5> = (fn & {
args: [arg1, arg2, arg3, arg4, arg5];
export type Call<
fn extends Fn,
arg0 = _,
arg1 = _,
arg2 = _,
arg3 = _
> = (fn & {
[rawArgs]: ExcludePlaceholders<[arg0, arg1, arg2, arg3]>;
})["return"];
/**
* Pipe a value through a list of functions.
* @description This is the same as the pipe operator in other languages.
* Evaluates the first function with the initial value, then passes the result to the second function, and so on.
* Calls the first function with the initial value, then passes the result to the second function, and so on.
*
* @param acc - The initial value to pass to the first function.
* @param xs - The list of functions to pipe the value through.
@@ -182,7 +118,7 @@ export type Pipe<acc, xs extends Fn[]> = xs extends [
/**
* Pipe a value through a list of functions.
* @description This is the same as the pipe operator in other languages.
* Evaluates the last function with the initial value, then passes the result to the second to last function, and so on.
* Calls the last function with the initial value, then passes the result to the second to last function, and so on.
*
* @param xs - The list of functions to pipe the value through.
* @param acc - The initial value to pass to the last function.

View File

@@ -1,11 +1,11 @@
import { unset, _ } from "../../core/Core";
import { IsNever } from "../../helpers";
import { Equal, IsNever } from "../../helpers";
type ExcludePlaceholders<xs, output extends any[] = []> = xs extends [
export type ExcludePlaceholders<xs, output extends any[] = []> = xs extends [
infer first,
...infer rest
]
? first extends _
? Equal<first, _> extends true
? ExcludePlaceholders<rest, output>
: ExcludePlaceholders<rest, [...output, first]>
: output;

View File

@@ -37,8 +37,8 @@ export namespace Functions {
* @example
* ```ts
* type T0 = Call<Parameter<1>, (a: number, b: string) => void>; // number
* type T1 = Call2<Parameter, (a: number, b: string) => void, 1>; // string
* type T2 = Eval<Parameter<(a: number, b: string) => void, 0>>; // number
* type T1 = Call<Parameter, (a: number, b: string) => void, 1>; // string
* type T2 = Call<Parameter<(a: number, b: string) => void, 0>>; // number
*/
export type Parameter<
N extends number | _ | unset = unset,
@@ -58,7 +58,7 @@ export namespace Functions {
* @example
* ```ts
* type T0 = Call<ReturnType, (a: number, b: string) => number>; // number
* type T1 = Eval<ReturnType<(a: number, b: string) => number>>; // number
* type T1 = Call<ReturnType<(a: number, b: string) => number>>; // number
* ```
*/
export type ReturnType<

View File

@@ -1,4 +1,4 @@
import { arg, Eval, Fn, PartialApply, unset } from "../../core/Core";
import { arg, Call, Fn, PartialApply, unset } from "../../core/Core";
import { Functions } from "../../functions/Functions";
import { Primitive, UnionToIntersection } from "../../helpers";
@@ -67,7 +67,7 @@ export type Match<value, patterns extends With<any, any>[]> = patterns extends [
]
? DoesMatch<value, pattern> extends true
? handler extends Fn
? Eval<PartialApply<Extract<handler, Fn>, ExtractArgs<value, pattern>>>
? Call<PartialApply<Extract<handler, Fn>, ExtractArgs<value, pattern>>>
: handler
: Match<value, restPatterns>
: never;

View File

@@ -1,4 +1,4 @@
import { Eval, Fn, PartialApply, unset, _ } from "../core/Core";
import { Call, Fn, PartialApply, unset, _ } from "../core/Core";
import * as Impl from "./impl/numbers";
import { Functions } from "../functions/Functions";
@@ -11,8 +11,8 @@ export namespace Numbers {
* @returns the sum of the two numbers
* @example
* ```ts
* type T0 = Eval<Numbers.Add<1, 2>>; // 3
* type T1 = Eval<Numbers.Add<999999999999999999999999999n, 2>>; // 1000000000000000000000000001n
* type T0 = Call<Numbers.Add<1, 2>>; // 3
* type T1 = Call<Numbers.Add<999999999999999999999999999n, 2>>; // 1000000000000000000000000001n
* ```
*/
export type Add<
@@ -38,8 +38,8 @@ export namespace Numbers {
* @returns the difference of the two numbers
* @example
* ```ts
* type T0 = Eval<Numbers.Sub<1, 2>>; // -1
* type T1 = Eval<Numbers.Sub<1000000000000000000000000001n, 2>>; // 999999999999999999999999999n
* type T0 = Call<Numbers.Sub<1, 2>>; // -1
* type T1 = Call<Numbers.Sub<1000000000000000000000000001n, 2>>; // 999999999999999999999999999n
* ```
*/
export type Sub<
@@ -65,8 +65,8 @@ export namespace Numbers {
* @returns the product of the two numbers
* @example
* ```ts
* type T0 = Eval<Numbers.Mul<99, 3>>; // 297
* type T1 = Eval<Numbers.Mul<999999999999999999999999999n, 2>>; // 1999999999999999999999999998n
* type T0 = Call<Numbers.Mul<99, 3>>; // 297
* type T1 = Call<Numbers.Mul<999999999999999999999999999n, 2>>; // 1999999999999999999999999998n
* ```
*/
export type Mul<
@@ -92,8 +92,8 @@ export namespace Numbers {
* @returns the quotient of the two numbers
* @example
* ```ts
* type T0 = Eval<Numbers.Div<99, 3>>; // 33
* type T1 = Eval<Numbers.Div<999999999999999999999999999n, 4>>; // 249999999999999999999999999n
* type T0 = Call<Numbers.Div<99, 3>>; // 33
* type T1 = Call<Numbers.Div<999999999999999999999999999n, 4>>; // 249999999999999999999999999n
* ```
*/
export type Div<
@@ -119,8 +119,8 @@ export namespace Numbers {
* @returns the remainder of the two numbers
* @example
* ```ts
* type T0 = Eval<Numbers.Mod<100, 3>>; // 1
* type T1 = Eval<Numbers.Mod<999999999999999999999999999n, 4>>; // 3n
* type T0 = Call<Numbers.Mod<100, 3>>; // 1
* type T1 = Call<Numbers.Mod<999999999999999999999999999n, 4>>; // 3n
* ```
*/
export type Mod<
@@ -145,8 +145,8 @@ export namespace Numbers {
* @returns the negated number
* @example
* ```ts
* type T0 = Eval<Numbers.Negate<1>>; // -1
* type T1 = Eval<Numbers.Negate<999999999999999999999999999n>>; // -999999999999999999999999999n
* type T0 = Call<Numbers.Negate<1>>; // -1
* type T1 = Call<Numbers.Negate<999999999999999999999999999n>>; // -999999999999999999999999999n
* ```
*/
export type Negate<n extends number | bigint | _ | unset = unset> =
@@ -165,8 +165,8 @@ export namespace Numbers {
* @returns the absolute value of the number
* @example
* ```ts
* type T0 = Eval<Numbers.Abs<-1>>; // 1
* type T1 = Eval<Numbers.Abs<999999999999999999999999999n>>; // 999999999999999999999999999n
* type T0 = Call<Numbers.Abs<-1>>; // 1
* type T1 = Call<Numbers.Abs<999999999999999999999999999n>>; // 999999999999999999999999999n
* ```
*/
export type Abs<n extends number | bigint | _ | unset = unset> = PartialApply<
@@ -187,7 +187,7 @@ export namespace Numbers {
* @returns the maximum values between the two
* @example
* ```ts
* type T0 = Eval<Numbers.Max<1, 2>>; // 2
* type T0 = Call<Numbers.Max<1, 2>>; // 2
* ```
*/
export type Max<
@@ -209,7 +209,7 @@ export namespace Numbers {
* @returns the minimum values between the two
* @example
* ```ts
* type T0 = Eval<Numbers.Min<1, 2>>; // 1
* type T0 = Call<Numbers.Min<1, 2>>; // 1
* ```
*/
export type Min<
@@ -232,7 +232,7 @@ export namespace Numbers {
* @returns the power of the two numbers
* @example
* ```ts
* type T0 = Eval<Numbers.Power<2, 128>>; // 340282366920938463463374607431768211456
* type T0 = Call<Numbers.Power<2, 128>>; // 340282366920938463463374607431768211456
* ```
*/
export type Power<
@@ -258,9 +258,9 @@ export namespace Numbers {
* @returns -1 if n1 < n2, 0 if n1 === n2, 1 if n1 > n2
* @example
* ```ts
* type T0 = Eval<Numbers.Compare<1, 2>>; // -1
* type T1 = Eval<Numbers.Compare<999999999999999999999999999n, 4>>; // 1
* type T2 = Eval<Numbers.Compare<999999999999999999999999999n, 999999999999999999999999999n>>; // 0
* type T0 = Call<Numbers.Compare<1, 2>>; // -1
* type T1 = Call<Numbers.Compare<999999999999999999999999999n, 4>>; // 1
* type T2 = Call<Numbers.Compare<999999999999999999999999999n, 999999999999999999999999999n>>; // 0
* ```
*/
export type Compare<
@@ -286,8 +286,8 @@ export namespace Numbers {
* @returns true if n1 === n2, false otherwise
* @example
* ```ts
* type T0 = Eval<Numbers.Equal<1, 2>>; // false
* type T1 = Eval<Numbers.Equal<2, 2>>; // true
* type T0 = Call<Numbers.Equal<1, 2>>; // false
* type T1 = Call<Numbers.Equal<2, 2>>; // true
* ```
*/
export type Equal<
@@ -313,8 +313,8 @@ export namespace Numbers {
* @returns true if n1 !== n2, false otherwise
* @example
* ```ts
* type T0 = Eval<Numbers.NotEqual<1, 2>>; // true
* type T1 = Eval<Numbers.NotEqual<2, 2>>; // false
* type T0 = Call<Numbers.NotEqual<1, 2>>; // true
* type T1 = Call<Numbers.NotEqual<2, 2>>; // false
* ```
*/
export type NotEqual<
@@ -340,9 +340,9 @@ export namespace Numbers {
* @returns true if n1 < n2, false otherwise
* @example
* ```ts
* type T0 = Eval<Numbers.LessThan<1, 2>>; // true
* type T1 = Eval<Numbers.LessThan<2, 2>>; // false
* type T2 = Eval<Numbers.LessThan<3, 2>>; // false
* type T0 = Call<Numbers.LessThan<1, 2>>; // true
* type T1 = Call<Numbers.LessThan<2, 2>>; // false
* type T2 = Call<Numbers.LessThan<3, 2>>; // false
* ```
*/
export type LessThan<
@@ -368,9 +368,9 @@ export namespace Numbers {
* @returns true if n1 <= n2, false otherwise
* @example
* ```ts
* type T0 = Eval<Numbers.LessThanOrEqual<1, 2>>; // true
* type T1 = Eval<Numbers.LessThanOrEqual<2, 2>>; // true
* type T2 = Eval<Numbers.LessThanOrEqual<3, 2>>; // false
* type T0 = Call<Numbers.LessThanOrEqual<1, 2>>; // true
* type T1 = Call<Numbers.LessThanOrEqual<2, 2>>; // true
* type T2 = Call<Numbers.LessThanOrEqual<3, 2>>; // false
* ```
*/
export type LessThanOrEqual<
@@ -399,9 +399,9 @@ export namespace Numbers {
* @returns true if n1 > n2, false otherwise
* @example
* ```ts
* type T0 = Eval<Numbers.GreaterThan<1, 2>>; // false
* type T1 = Eval<Numbers.GreaterThan<2, 2>>; // false
* type T2 = Eval<Numbers.GreaterThan<3, 2>>; // true
* type T0 = Call<Numbers.GreaterThan<1, 2>>; // false
* type T1 = Call<Numbers.GreaterThan<2, 2>>; // false
* type T2 = Call<Numbers.GreaterThan<3, 2>>; // true
* ```
*/
export type GreaterThan<
@@ -427,9 +427,9 @@ export namespace Numbers {
* @returns true if n1 >= n2, false otherwise
* @example
* ```ts
* type T0 = Eval<Numbers.GreaterThanOrEqual<1, 2>>; // false
* type T1 = Eval<Numbers.GreaterThanOrEqual<2, 2>>; // true
* type T2 = Eval<Numbers.GreaterThanOrEqual<3, 2>>; // true
* type T0 = Call<Numbers.GreaterThanOrEqual<1, 2>>; // false
* type T1 = Call<Numbers.GreaterThanOrEqual<2, 2>>; // true
* type T2 = Call<Numbers.GreaterThanOrEqual<3, 2>>; // true
* ```
*/
export type GreaterThanOrEqual<

View File

@@ -1,5 +1,5 @@
import { IsArrayStrict, Prettify } from "../helpers";
import { Call, Call2, Fn, PartialApply, unset, _ } from "../core/Core";
import { Call, Fn, PartialApply, unset, _ } from "../core/Core";
import { Std } from "../std/Std";
import { Strings } from "../strings/Strings";
import * as Impl from "./impl/objects";
@@ -32,7 +32,7 @@ export namespace Objects {
}
type MapValuesImpl<T, fn extends Fn> = {
[K in keyof T]: Call2<fn, T[K], K>;
[K in keyof T]: Call<fn, T[K], K>;
};
/**
@@ -273,7 +273,7 @@ export namespace Objects {
entries extends [PropertyKey, any],
fn extends Fn
> = entries extends any
? Call2<fn, entries[1], entries[0]> extends true
? Call<fn, entries[1], entries[0]> extends true
? entries
: never
: never;
@@ -304,7 +304,7 @@ export namespace Objects {
entries extends [PropertyKey, any],
fn extends Fn
> = entries extends any
? Call2<fn, entries[1], entries[0]> extends true
? Call<fn, entries[1], entries[0]> extends true
? never
: entries
: never;
@@ -316,8 +316,8 @@ export namespace Objects {
* @example
* ```ts
* type T0 = Call<Objects.Assign<{ a: string }>, { b: number }>; // { a: string, b: number }
* type T1 = Eval<Objects.Assign<{ a: string }, { b: number }>>; // { a: string, b: number }
* type T2 = Eval<Objects.Assign<{ a: 1 }, { b: 1 }, { c: 1 }>>; // { a: 1, b: 1, c: 1 }
* type T1 = Call<Objects.Assign<{ a: string }, { b: number }>>; // { a: string, b: number }
* type T2 = Call<Objects.Assign<{ a: 1 }, { b: 1 }, { c: 1 }>>; // { a: 1, b: 1, c: 1 }
* ```
*/
export type Assign<
@@ -340,7 +340,7 @@ export namespace Objects {
* @example
* ```ts
* type T0 = Call<Objects.Readonly, { a: 1; b: true }>; // { readonly a:1; readonly b: true}
* type T1 = Eval<Objects.Readonly<{ a: 1; b: true }>>; // { readonly a:1; readonly b: true}
* type T1 = Call<Objects.Readonly<{ a: 1; b: true }>>; // { readonly a:1; readonly b: true}
* ```
*/
export type Readonly<value = unset> = PartialApply<ReadonlyFn, [value]>;
@@ -357,7 +357,7 @@ export namespace Objects {
* @example
* ```ts
* type T0 = Call<Objects.Required, { a?: 1; b?: true }>; // { a:1; b: true}
* type T1 = Eval<Objects.Required<{ a?: 1; b?: true }>>; // { a:1; b: true}
* type T1 = Call<Objects.Required<{ a?: 1; b?: true }>>; // { a:1; b: true}
* ```
*/
export type Required<value = unset> = PartialApply<RequiredFn, [value]>;
@@ -374,7 +374,7 @@ export namespace Objects {
* @example
* ```ts
* type T0 = Call<Objects.Partial, { a: 1; b: true }>; // { a?:1; b?: true}
* type T1 = Eval<Objects.Partial<{ a: 1; b: true }>>; // { a?:1; b?: true}
* type T1 = Call<Objects.Partial<{ a: 1; b: true }>>; // { a?:1; b?: true}
* ```
*/
export type Partial<value = unset> = PartialApply<PartialFn, [value]>;

View File

@@ -445,9 +445,9 @@ export namespace Strings {
* @returns The result of the comparison.
* @example
* ```ts
* type T0 = Call2<Strings.Compare,"abc","def">; // -1
* type T1 = Call2<Strings.Compare,"def","abc">; // 1
* type T2 = Call2<Strings.Compare,"abc","abc">; // 0
* type T0 = Call<Strings.Compare,"abc","def">; // -1
* type T1 = Call<Strings.Compare,"def","abc">; // 1
* type T2 = Call<Strings.Compare,"abc","abc">; // 0
* ```
*/
export type Compare<
@@ -474,9 +474,9 @@ export namespace Strings {
* @returns True if the first string is lexically less than the second string, false otherwise.
* @example
* ```ts
* type T0 = Call2<Strings.LessThan,"abc","def">; // true
* type T1 = Call2<Strings.LessThan,"def","abc">; // false
* type T2 = Call2<Strings.LessThan,"abc","abc">; // false
* type T0 = Call<Strings.LessThan,"abc","def">; // true
* type T1 = Call<Strings.LessThan,"def","abc">; // false
* type T2 = Call<Strings.LessThan,"abc","abc">; // false
* ```
*/
export type LessThan<
@@ -503,9 +503,9 @@ export namespace Strings {
* @returns True if the first string is lexically less than or equal to the second string, false otherwise.
* @example
* ```ts
* type T0 = Call2<Strings.LessThanOrEqual,"abc","def">; // true
* type T1 = Call2<Strings.LessThanOrEqual,"def","abc">; // false
* type T2 = Call2<Strings.LessThanOrEqual,"abc","abc">; // true
* type T0 = Call<Strings.LessThanOrEqual,"abc","def">; // true
* type T1 = Call<Strings.LessThanOrEqual,"def","abc">; // false
* type T2 = Call<Strings.LessThanOrEqual,"abc","abc">; // true
*/
export type LessThanOrEqual<
n1 extends string | _ | unset = unset,
@@ -534,9 +534,9 @@ export namespace Strings {
* @returns True if the first string is lexically greater than the second string, false otherwise.
* @example
* ```ts
* type T0 = Call2<Strings.GreaterThan,"abc","def">; // false
* type T1 = Call2<Strings.GreaterThan,"def","abc">; // true
* type T2 = Call2<Strings.GreaterThan,"abc","abc">; // false
* type T0 = Call<Strings.GreaterThan,"abc","def">; // false
* type T1 = Call<Strings.GreaterThan,"def","abc">; // true
* type T2 = Call<Strings.GreaterThan,"abc","abc">; // false
* ```
*/
export type GreaterThan<
@@ -563,9 +563,9 @@ export namespace Strings {
* @returns True if the first string is lexically greater than or equal to the second string, false otherwise.
* @example
* ```ts
* type T0 = Call2<Strings.GreaterThanOrEqual,"abc","def">; // false
* type T1 = Call2<Strings.GreaterThanOrEqual,"def","abc">; // true
* type T2 = Call2<Strings.GreaterThanOrEqual,"abc","abc">; // true
* type T0 = Call<Strings.GreaterThanOrEqual,"abc","def">; // false
* type T1 = Call<Strings.GreaterThanOrEqual,"def","abc">; // true
* type T2 = Call<Strings.GreaterThanOrEqual,"abc","abc">; // true
* ```
*/
export type GreaterThanOrEqual<

View File

@@ -1,4 +1,4 @@
import { Call2 } from "../../core/Core";
import { Call } from "../../core/Core";
import { Numbers } from "../../numbers/Numbers";
import { StringToTuple } from "./split";
import { Equal as _Equal } from "../../helpers";
@@ -37,7 +37,7 @@ type CharacterCompare<
? 0
: Char1 extends keyof ascii
? Char2 extends keyof ascii
? Call2<Numbers.Compare, ascii[Char1], ascii[Char2]>
? Call<Numbers.Compare, ascii[Char1], ascii[Char2]>
: 1
: -1;

View File

@@ -1,13 +1,9 @@
import { Functions as F, Functions } from "../functions/Functions";
import { Numbers as N, Numbers } from "../numbers/Numbers";
import {
Apply,
args,
Call,
Call2,
Call3,
Eval,
Fn,
PartialApply,
Pipe,
@@ -36,8 +32,8 @@ export namespace Tuples {
* @returns The element at the specified index.
* @example
* ```ts
* type T0 = Call2<Tuples.At, 1, ["a", "b", "c"]>; // "b"
* type T1 = Eval<Tuples.At<1, ["a", "b", "c"]>>; // "b"
* type T0 = Call<Tuples.At, 1, ["a", "b", "c"]>; // "b"
* type T1 = Call<Tuples.At<1, ["a", "b", "c"]>>; // "b"
* type T2 = Call<Tuples.At<1>, ["a", "b", "c"]>; // "b"
* ```
*/
@@ -68,7 +64,7 @@ export namespace Tuples {
* ```ts
* type T0 = Call<Tuples.IsEmpty, []>; // true
* type T1 = Call<Tuples.IsEmpty, [1, 2, 3]>; // false
* type T2 = Eval<Tuples.IsEmpty<[]>>; // true
* type T2 = Call<Tuples.IsEmpty<[]>>; // true
* ```
*/
export type IsEmpty<tuple = unset> = PartialApply<IsEmptyFn, [tuple]>;
@@ -84,7 +80,7 @@ export namespace Tuples {
* @example
* ```ts
* type T0 = Call<Tuples.ToUnion, [1, 2, 3]>; // 1 | 2 | 3
* type T1 = Eval<Tuples.ToUnion<[1, 2, 3]>>; // 1 | 2 | 3
* type T1 = Call<Tuples.ToUnion<[1, 2, 3]>>; // 1 | 2 | 3
* ```
*/
export type ToUnion<tuple extends readonly any[] | _ | unset = unset> =
@@ -106,7 +102,7 @@ export namespace Tuples {
interface ToIntersectionFn extends Fn {
return: this["args"] extends [infer tuples extends readonly any[], ...any]
? Eval<Tuples.Reduce<IntersectFn, unknown, tuples>>
? Call<Tuples.Reduce<IntersectFn, unknown, tuples>>
: never;
}
@@ -227,19 +223,19 @@ export namespace Tuples {
interface FlatMapFn extends Fn {
return: ReduceImpl<
this["arg1"],
FlatMapReducer<Extract<this["arg0"], Fn>>,
[],
FlatMapReducer<Extract<this["arg0"], Fn>>
this["arg1"]
>;
}
type ReduceImpl<xs, acc, fn extends Fn> = xs extends [
type ReduceImpl<fn extends Fn, acc, xs> = xs extends [
infer first,
...infer rest
]
? ReduceImpl<rest, Call2<fn, acc, first>, fn>
? ReduceImpl<fn, Call<fn, acc, first>, rest>
: xs extends readonly [infer first, ...infer rest]
? ReduceImpl<rest, Call2<fn, acc, first>, fn>
? ReduceImpl<fn, Call<fn, acc, first>, rest>
: acc;
/**
@@ -261,14 +257,14 @@ export namespace Tuples {
> = PartialApply<ReduceFn, [fn, init, tuple]>;
interface ReduceFn extends Fn {
return: ReduceImpl<this["arg2"], this["arg1"], Extract<this["arg0"], Fn>>;
return: ReduceImpl<Extract<this["arg0"], Fn>, this["arg1"], this["arg2"]>;
}
type ReduceRightImpl<xs, acc, fn extends Fn> = xs extends [
...infer rest,
infer last
]
? ReduceRightImpl<rest, Call2<fn, acc, last>, fn>
? ReduceRightImpl<rest, Call<fn, acc, last>, fn>
: acc;
/**
@@ -323,9 +319,9 @@ export namespace Tuples {
export interface FilterFn extends Fn {
return: ReduceImpl<
this["arg1"],
FilterReducer<Extract<this["arg0"], Fn>>,
[],
FilterReducer<Extract<this["arg0"], Fn>>
this["arg1"]
>;
}
@@ -333,7 +329,7 @@ export namespace Tuples {
infer first,
...infer rest
]
? Call2<fn, first, index["length"]> extends true
? Call<fn, first, index["length"]> extends true
? first
: FindImpl<rest, fn, [...index, any]>
: never;
@@ -374,7 +370,7 @@ export namespace Tuples {
>;
interface SumFn extends Fn {
return: ReduceImpl<this["arg0"], 0, N.Add>;
return: ReduceImpl<N.Add, 0, this["arg0"]>;
}
type DropImpl<
@@ -454,7 +450,7 @@ export namespace Tuples {
index extends any[] = [],
output extends any[] = []
> = xs extends readonly [infer head, ...infer tail]
? Call2<fn, head, index["length"]> extends true
? Call<fn, head, index["length"]> extends true
? TakeWhileImpl<tail, fn, [...index, any], [...output, head]>
: output
: output;
@@ -535,7 +531,7 @@ export namespace Tuples {
infer head,
...infer tail
]
? Eval<
? Call<
Tuples.Partition<PartialApply<predicateFn, [_, head]>, tail>
> extends [infer left extends any[], infer right extends any[]]
? [...SortImpl<left, predicateFn>, head, ...SortImpl<right, predicateFn>]
@@ -576,8 +572,8 @@ export namespace Tuples {
* @example
* ```ts
* type T0 = Call<Tuples.Join<",">,["a","b","c"]>; // "a,b,c"
* type T1 = Call2<Tuples.Join,",",["a","b","c"]>; // "a,b,c"
* type T2 = Eval<Tuples.Join<",",["a","b","c"]>>; // "a,b,c"
* type T1 = Call<Tuples.Join,",",["a","b","c"]>; // "a,b,c"
* type T2 = Call<Tuples.Join<",",["a","b","c"]>>; // "a,b,c"
* ```
*/
export type Join<
@@ -587,7 +583,7 @@ export namespace Tuples {
interface JoinFn extends Fn {
return: this["args"] extends [infer Sep extends string, infer Tuple]
? ReduceImpl<Tuple, "", JoinReducer<Sep>>
? ReduceImpl<JoinReducer<Sep>, "", Tuple>
: never;
}
@@ -639,7 +635,7 @@ export namespace Tuples {
* @returns [...tuple1, ...tuple2]
* @example
* ```ts
* type T0 = Call2<Tuples.Concat, [1], [2, 3]>; // [1, 2, 3]
* type T0 = Call<Tuples.Concat, [1], [2, 3]>; // [1, 2, 3]
* ```
*/
export type Concat<tuple1 = unset, tuple2 = unset> = PartialApply<
@@ -696,7 +692,7 @@ export namespace Tuples {
interface ZipWithMapper<fn extends Fn, arrs extends unknown[][]> extends Fn {
return: this["args"] extends [infer Index extends number, ...any]
? Apply<fn, Eval<Tuples.Map<Tuples.At<Index>, arrs>>>
? Apply<fn, Call<Tuples.Map<Tuples.At<Index>, arrs>>>
: never;
}
@@ -725,8 +721,8 @@ export namespace Tuples {
* @returns The zipped tuple.
* @example
* ```ts
* type T0 = Call2<Tuples.Zip, [1, 2, 3], [10, 2, 5]>; // [[1, 10], [2, 2], [3, 5]]
* type T1 = Eval<Tuples.Zip<[1, 2, 3], [10, 2, 5]>>; // [[1, 10], [2, 2], [3, 5]]
* type T0 = Call<Tuples.Zip, [1, 2, 3], [10, 2, 5]>; // [[1, 10], [2, 2], [3, 5]]
* type T1 = Call<Tuples.Zip<[1, 2, 3], [10, 2, 5]>>; // [[1, 10], [2, 2], [3, 5]]
* ```
*/
export type Zip<
@@ -757,9 +753,9 @@ export namespace Tuples {
* @returns The zipped tuple.
* @example
* ```ts
* type T0 = Call2<Tuples.ZipWith<args>, [1, 2, 3], [10, 2, 5]>; // [[1, 10], [2, 2], [3, 5]]
* type T1 = Eval<Tuples.ZipWith<args, [1, 2, 3], [10, 2, 5]>>; // [[1, 10], [2, 2], [3, 5]]
* type T3 = Call2<Tuples.ZipWith<N.Add>, [1, 2, 3], [10, 2, 5]>; // [11, 4, 8]
* type T0 = Call<Tuples.ZipWith<args>, [1, 2, 3], [10, 2, 5]>; // [[1, 10], [2, 2], [3, 5]]
* type T1 = Call<Tuples.ZipWith<args, [1, 2, 3], [10, 2, 5]>>; // [[1, 10], [2, 2], [3, 5]]
* type T3 = Call<Tuples.ZipWith<N.Add>, [1, 2, 3], [10, 2, 5]>; // [11, 4, 8]
* ```
*/
export type ZipWith<
@@ -832,9 +828,9 @@ export namespace Tuples {
* @example
* ```ts
* type T0 = Call<Tuples.Range<3>, 7>; // [3, 4, 5, 6, 7]
* type T1 = Eval<Tuples.Range<_, 10>, 5>; // [5, 6, 7, 8, 9, 10]
* type T3 = Eval<Tuples.Range< -2, 2>, 5>; // [-2, 1, 0, 1, 2]
* type T4 = Eval<Tuples.Range< -5, -2>, 5>; // [-5, -4, -3, -2]
* type T1 = Call<Tuples.Range<_, 10>, 5>; // [5, 6, 7, 8, 9, 10]
* type T3 = Call<Tuples.Range< -2, 2>, 5>; // [-2, 1, 0, 1, 2]
* type T4 = Call<Tuples.Range< -5, -2>, 5>; // [-5, -4, -3, -2]
* ```
*/
export type Range<
@@ -847,7 +843,7 @@ export namespace Tuples {
infer start extends number,
infer end extends number
]
? Call2<Numbers.LessThanOrEqual, start, end> extends true
? Call<Numbers.LessThanOrEqual, start, end> extends true
? Pipe<
start,
[Numbers.Sub<end, _>, Numbers.Add<1>, Numbers.Abs]
@@ -867,7 +863,7 @@ export namespace Tuples {
: RangeImpl<
start,
length,
[...output, Eval<Numbers.Add<start, output["length"]>>]
[...output, Call<Numbers.Add<start, output["length"]>>]
>;
/**
@@ -877,8 +873,8 @@ export namespace Tuples {
* @example
* ```ts
* type T0 = Call<Tuples.Length, [1, 2, 3]>; // 3
* type T1 = Eval<Tuples.Length, []>; 0
* type T2 = Eval<Tuples.Length, ['a']>; 1
* type T1 = Call<Tuples.Length, []>; 0
* type T2 = Call<Tuples.Length, ['a']>; 1
* ```
*/
export type Length<tuple extends readonly any[] | _ | unset = unset> =
@@ -898,7 +894,7 @@ export namespace Tuples {
* ```ts
* type T0 = Call<Tuples.Min, [1, 2, 3]>; // 1
* type T1 = Call<Tuples.Min, [-1, -2, -3]>; // -3
* type T2 = Eval<Tuples.Min, []>; never
* type T2 = Call<Tuples.Min, []>; never
* ```
*/
export type Min<tuple extends readonly any[] | _ | unset = unset> =
@@ -928,7 +924,7 @@ export namespace Tuples {
* ```ts
* type T0 = Call<Tuples.Max, [1, 2, 3]>; // 3
* type T1 = Call<Tuples.Max, [-1, -2, -3]>; // -1
* type T2 = Eval<Tuples.Max, []>; never
* type T2 = Call<Tuples.Max, []>; never
* ```
*/
export type Max<tuple extends readonly any[] | _ | unset = unset> =

View File

@@ -1,4 +1,4 @@
import { Call, Eval, Fn, PartialApply, unset, _ } from "../core/Core";
import { Call, Fn, PartialApply, unset, _ } from "../core/Core";
import { Functions } from "../functions/Functions";
import { UnionToIntersection, UnionToTuple } from "../helpers";
import { Std } from "../std/Std";
@@ -70,9 +70,9 @@ export namespace Unions {
* @example
* ```ts
* type T0 = Call<Unions.Range<3>, 7>; // 3 | 4 | 5 | 6 | 7
* type T1 = Eval<Unions.Range<_, 10>, 5>; // 5 | 6 | 7 | 8 | 9 | 10
* type T3 = Eval<Unions.Range< -2, 2>, 5>; // -2 | 1 | 0 | 1 | 2
* type T4 = Eval<Unions.Range< -5, -2>, 5>; // -5 | -4 | -3 | -2
* type T1 = Call<Unions.Range<_, 10>, 5>; // 5 | 6 | 7 | 8 | 9 | 10
* type T3 = Call<Unions.Range< -2, 2>, 5>; // -2 | 1 | 0 | 1 | 2
* type T4 = Call<Unions.Range< -5, -2>, 5>; // -5 | -4 | -3 | -2
* ```
*/
export type Range<
@@ -85,7 +85,7 @@ export namespace Unions {
infer start extends number,
infer end extends number
]
? Eval<Tuples.Range<start, end>>[number]
? Call<Tuples.Range<start, end>>[number]
: never;
}
@@ -115,7 +115,7 @@ export namespace Unions {
* ```ts
* type T0 = Call<Unions.NonNullable, "a" | 1 | null | undefined>; // 1 | "a"
* type T1 = Pipe<"a" | 1 | null | undefined, [U.NonNullable]>; // 1 | "a"
* type T2 = Eval<Unions.NonNullable<"a" | 1 | null | undefined>>; // 1 | "a"
* type T2 = Call<Unions.NonNullable<"a" | 1 | null | undefined>>; // 1 | "a"
* ```
*/
export type NonNullable<union = unset> = PartialApply<NonNullableFn, [union]>;

View File

@@ -1,34 +1,34 @@
import { Call, Eval, Tuples, Booleans, T, _ } from "../src/index";
import { $, Tuples, Booleans, T, _ } from "../src/index";
import { Equal, Expect } from "../src/internals/helpers";
describe("Booleans", () => {
describe("And", () => {
it("can be called without any pre-filled arguments", () => {
type res1 = Call<Tuples.Reduce<Booleans.And, true>, [true, true, false]>;
type res1 = $<Tuples.Reduce<Booleans.And, true>, [true, true, false]>;
// ^?
type test1 = Expect<Equal<res1, false>>;
});
it("can be called with one pre-filled argument", () => {
type res1 = Call<Tuples.Map<Booleans.And<true>>, [true, false, true]>;
type res1 = $<Tuples.Map<Booleans.And<true>>, [true, false, true]>;
// ^?
type test1 = Expect<Equal<res1, [true, false, true]>>;
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Booleans.And<true, true>>;
type res1 = $<Booleans.And<true, true>>;
// ^?
type test1 = Expect<Equal<res1, true>>;
type res2 = Eval<Booleans.And<false, false>>;
type res2 = $<Booleans.And<false, false>>;
// ^?
type test2 = Expect<Equal<res2, false>>;
type res3 = Eval<Booleans.And<true, false>>;
type res3 = $<Booleans.And<true, false>>;
// ^?
type test3 = Expect<Equal<res3, false>>;
type res4 = Eval<Booleans.And<false, true>>;
type res4 = $<Booleans.And<false, true>>;
// ^?
type test4 = Expect<Equal<res4, false>>;
});
@@ -36,31 +36,31 @@ describe("Booleans", () => {
describe("Or", () => {
it("can be called without any pre-filled arguments", () => {
type res1 = Call<Tuples.Reduce<Booleans.Or, false>, [false, true, false]>;
type res1 = $<Tuples.Reduce<Booleans.Or, false>, [false, true, false]>;
// ^?
type test1 = Expect<Equal<res1, true>>;
});
it("can be called with one pre-filled argument", () => {
type res1 = Call<Tuples.Map<Booleans.Or<true>>, [true, false, true]>;
type res1 = $<Tuples.Map<Booleans.Or<true>>, [true, false, true]>;
// ^?
type test1 = Expect<Equal<res1, [true, true, true]>>;
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Booleans.Or<false, false>>;
type res1 = $<Booleans.Or<false, false>>;
// ^?
type test1 = Expect<Equal<res1, false>>;
type res2 = Eval<Booleans.Or<true, false>>;
type res2 = $<Booleans.Or<true, false>>;
// ^?
type test2 = Expect<Equal<res2, true>>;
type res3 = Eval<Booleans.Or<false, true>>;
type res3 = $<Booleans.Or<false, true>>;
// ^?
type test3 = Expect<Equal<res3, true>>;
type res4 = Eval<Booleans.Or<true, true>>;
type res4 = $<Booleans.Or<true, true>>;
// ^?
type test4 = Expect<Equal<res4, true>>;
});
@@ -68,87 +68,87 @@ describe("Booleans", () => {
describe("XOr", () => {
it("can be called without any pre-filled arguments", () => {
type res1 = Call<Tuples.Reduce<Booleans.XOr, true>, [false, true, false]>;
type res1 = $<Tuples.Reduce<Booleans.XOr, true>, [false, true, false]>;
// ^?
type test1 = Expect<Equal<res1, false>>;
});
it("can be called with one pre-filled argument", () => {
type res1 = Call<Tuples.Map<Booleans.XOr<true>>, [true, false, true]>;
type res1 = $<Tuples.Map<Booleans.XOr<true>>, [true, false, true]>;
// ^?
type test1 = Expect<Equal<res1, [false, true, false]>>;
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Booleans.XOr<true, true>>;
type res1 = $<Booleans.XOr<true, true>>;
// ^?
type test1 = Expect<Equal<res1, false>>;
type res2 = Eval<Booleans.XOr<false, false>>;
type res2 = $<Booleans.XOr<false, false>>;
// ^?
type test2 = Expect<Equal<res2, false>>;
type res3 = Eval<Booleans.XOr<true, false>>;
type res3 = $<Booleans.XOr<true, false>>;
// ^?
type test3 = Expect<Equal<res3, true>>;
type res4 = Eval<Booleans.XOr<false, true>>;
type res4 = $<Booleans.XOr<false, true>>;
// ^?
type test4 = Expect<Equal<res4, true>>;
});
});
it("Not", () => {
type res1 = Call<Booleans.Not, true>;
type res1 = $<Booleans.Not, true>;
// ^?
type test1 = Expect<Equal<res1, false>>;
type res2 = Eval<Booleans.Not<true>>;
type res2 = $<Booleans.Not<true>>;
// ^?
type test2 = Expect<Equal<res2, false>>;
});
describe("Extends", () => {
it("should check if a type is assignable to another type", () => {
type res1 = Call<Booleans.Extends<".">, [1, 2, 3]>;
type res1 = $<Booleans.Extends<".">, [1, 2, 3]>;
// ^?
type test1 = Expect<Equal<res1, false>>;
type res2 = Eval<Booleans.Extends<"a", string>>;
type res2 = $<Booleans.Extends<"a", string>>;
// ^?
type test2 = Expect<Equal<res2, true>>;
type res3 = Eval<Booleans.Extends<string, "a">>;
type res3 = $<Booleans.Extends<string, "a">>;
// ^?
type test3 = Expect<Equal<res3, false>>;
});
it("should reverse it's function arguments when partial applied", () => {
type res4 = Eval<Booleans.Extends<1, number>>;
type res4 = $<Booleans.Extends<1, number>>;
type test4 = Expect<Equal<res4, true>>;
type res5 = Call<Booleans.Extends<_, 2>, 1>;
type res5 = $<Booleans.Extends<_, 2>, 1>;
type test5 = Expect<Equal<res5, false>>;
type res6 = Call<T.Map<Booleans.Extends<_, number>>, [1, "2", 3]>;
type res6 = $<T.Map<Booleans.Extends<_, number>>, [1, "2", 3]>;
type test6 = Expect<Equal<res6, [true, false, true]>>;
type res7 = Call<Booleans.Extends<number>, 1>;
type res7 = $<Booleans.Extends<number>, 1>;
type test7 = Expect<Equal<res7, true>>;
type res8 = Call<T.Map<Booleans.Extends<number>>, [1, "2", 3]>;
type res8 = $<T.Map<Booleans.Extends<number>>, [1, "2", 3]>;
type test8 = Expect<Equal<res8, [true, false, true]>>;
});
});
it("Equals", () => {
type res1 = Call<Booleans.Equals<".">, ".">;
type res1 = $<Booleans.Equals<".">, ".">;
// ^?
type test1 = Expect<Equal<res1, true>>;
});
it("DoesNotExtend", () => {
type res1 = Call<Booleans.DoesNotExtend<"a">, "b">;
type res1 = $<Booleans.DoesNotExtend<"a">, "b">;
// ^?
type test1 = Expect<Equal<res1, true>>;
});

View File

@@ -1,5 +1,5 @@
import { Call, F, _ } from "../src/index";
import { Call2 } from "../src/internals/core/Core";
import { F, _ } from "../src/index";
import { Call } from "../src/internals/core/Core";
import { Equal, Expect } from "../src/internals/helpers";
describe("Functions", () => {
@@ -13,7 +13,7 @@ describe("Functions", () => {
type res1 = Call<F.Parameter<0>, (a: string, b: number) => void>;
// ^?
type tes1 = Expect<Equal<res1, string>>;
type res2 = Call2<F.Parameter, (a: string, b: number) => void, 0>;
type res2 = Call<F.Parameter, (a: string, b: number) => void, 0>;
// ^?
type tes2 = Expect<Equal<res2, string>>;
});

View File

@@ -1,6 +1,6 @@
import {
Booleans,
Eval,
Call,
Functions,
Match,
Numbers,
@@ -20,7 +20,7 @@ import { Equal, Expect } from "../src/internals/helpers";
describe("Match", () => {
it("should match with regular types", () => {
type MatchTest<T> = Eval<
type MatchTest<T> = Call<
Match<
T,
[
@@ -46,7 +46,7 @@ describe("Match", () => {
});
it("should work with patterns destructuring arguments", () => {
type MatchTest<T> = Eval<
type MatchTest<T> = Call<
Match<
T,
[
@@ -87,7 +87,7 @@ describe("Match", () => {
});
it("should work with constrained arguments", () => {
type MatchTest<T> = Eval<
type MatchTest<T> = Call<
Match<
T,
[
@@ -112,7 +112,7 @@ describe("Match", () => {
});
it("Handlers can also be regular values", () => {
type MatchTest<T> = Eval<
type MatchTest<T> = Call<
Match<
T,
[
@@ -139,7 +139,7 @@ describe("Match", () => {
describe("Composition", () => {
it("Map and Match", () => {
type Transform<xs extends any[]> = Eval<
type Transform<xs extends any[]> = Call<
Tuples.Map<
Match<
[

View File

@@ -1,4 +1,4 @@
import { Call, Call2, Eval, Numbers, Tuples, _, T } from "../src/index";
import { Call, Numbers, Tuples, _, T } from "../src/index";
import { Equal, Expect } from "../src/internals/helpers";
describe("Numbers", () => {
@@ -18,7 +18,7 @@ describe("Numbers", () => {
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Numbers.Add<1, 2>>;
type res1 = Call<Numbers.Add<1, 2>>;
// ^?
type test1 = Expect<Equal<res1, 3>>;
@@ -31,7 +31,7 @@ describe("Numbers", () => {
// ^?
type test1 = Expect<Equal<res1, -6>>;
type res2 = Call2<Numbers.Sub, 0, 1>;
type res2 = Call<Numbers.Sub, 0, 1>;
// ^?
type test2 = Expect<Equal<res2, -1>>;
});
@@ -43,7 +43,7 @@ describe("Numbers", () => {
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Numbers.Sub<1, 2>>;
type res1 = Call<Numbers.Sub<1, 2>>;
// ^?
type test1 = Expect<Equal<res1, -1>>;
});
@@ -66,11 +66,11 @@ describe("Numbers", () => {
// ^?
type test1 = Expect<Equal<res1, 12>>;
type res2 = Call2<Numbers.Mul, 3, 2>;
type res2 = Call<Numbers.Mul, 3, 2>;
// ^?
type test2 = Expect<Equal<res2, 6>>;
type res3 = Call2<Numbers.Mul, 3, -2>;
type res3 = Call<Numbers.Mul, 3, -2>;
// ^?
type test3 = Expect<Equal<res3, -6>>;
});
@@ -82,7 +82,7 @@ describe("Numbers", () => {
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Numbers.Mul<3, 2>>;
type res1 = Call<Numbers.Mul<3, 2>>;
// ^?
type test1 = Expect<Equal<res1, 6>>;
});
@@ -94,7 +94,7 @@ describe("Numbers", () => {
// ^?
type test1 = Expect<Equal<res1, 3>>;
type res2 = Call2<Numbers.Div, 6, 2>;
type res2 = Call<Numbers.Div, 6, 2>;
// ^?
type test2 = Expect<Equal<res2, 3>>;
});
@@ -106,7 +106,7 @@ describe("Numbers", () => {
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Numbers.Div<6, 2>>;
type res1 = Call<Numbers.Div<6, 2>>;
// ^?
type test1 = Expect<Equal<res1, 3>>;
});
@@ -114,7 +114,7 @@ describe("Numbers", () => {
describe("Mod", () => {
it("can be called without any pre-filled arguments", () => {
type res2 = Call2<Numbers.Mod, 5, 3>;
type res2 = Call<Numbers.Mod, 5, 3>;
// ^?
type test2 = Expect<Equal<res2, 2>>;
});
@@ -126,7 +126,7 @@ describe("Numbers", () => {
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Numbers.Mod<5, 3>>;
type res1 = Call<Numbers.Mod<5, 3>>;
// ^?
type test1 = Expect<Equal<res1, 2>>;
});
@@ -140,7 +140,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.Negate<100>>;
type res1 = Call<Numbers.Negate<100>>;
// ^?
type test1 = Expect<Equal<res1, -100>>;
});
@@ -154,7 +154,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.Abs<-100>>;
type res1 = Call<Numbers.Abs<-100>>;
// ^?
type test1 = Expect<Equal<res1, 100>>;
});
@@ -166,11 +166,11 @@ describe("Numbers", () => {
// ^?
type test1 = Expect<Equal<res1, 64>>;
type res2 = Call2<Numbers.Power, 2, 3>;
type res2 = Call<Numbers.Power, 2, 3>;
// ^?
type test2 = Expect<Equal<res2, 8>>;
type res3 = Call2<Numbers.Power, 2, -3>;
type res3 = Call<Numbers.Power, 2, -3>;
// ^?
type test3 = Expect<Equal<res3, 0>>;
});
@@ -182,7 +182,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.Power<2, 3>>;
type res1 = Call<Numbers.Power<2, 3>>;
// ^?
type test1 = Expect<Equal<res1, 8>>;
});
@@ -194,11 +194,11 @@ describe("Numbers", () => {
// ^?
type test1 = Expect<Equal<res1, 1>>;
type res2 = Call2<Numbers.Min, 2, 3>;
type res2 = Call<Numbers.Min, 2, 3>;
// ^?
type test2 = Expect<Equal<res2, 2>>;
type res3 = Call2<Numbers.Min, 2, -3>;
type res3 = Call<Numbers.Min, 2, -3>;
// ^?
type test3 = Expect<Equal<res3, -3>>;
});
@@ -210,7 +210,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.Min<2, 3>>;
type res1 = Call<Numbers.Min<2, 3>>;
// ^?
type test1 = Expect<Equal<res1, 2>>;
});
@@ -222,11 +222,11 @@ describe("Numbers", () => {
// ^?
type test1 = Expect<Equal<res1, 3>>;
type res2 = Call2<Numbers.Max, 2, 3>;
type res2 = Call<Numbers.Max, 2, 3>;
// ^?
type test2 = Expect<Equal<res2, 3>>;
type res3 = Call2<Numbers.Max, 2, -3>;
type res3 = Call<Numbers.Max, 2, -3>;
// ^?
type test3 = Expect<Equal<res3, 2>>;
});
@@ -238,7 +238,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.Max<2, 3>>;
type res1 = Call<Numbers.Max<2, 3>>;
// ^?
type test1 = Expect<Equal<res1, 3>>;
});
@@ -246,15 +246,15 @@ describe("Numbers", () => {
describe("Compare", () => {
it("can be called without any pre-filled arguments", () => {
type res1 = Call2<Numbers.Compare, 3, 2>;
type res1 = Call<Numbers.Compare, 3, 2>;
// ^?
type test1 = Expect<Equal<res1, 1>>;
type res2 = Call2<Numbers.Compare, 2, 3>;
type res2 = Call<Numbers.Compare, 2, 3>;
// ^?
type test2 = Expect<Equal<res2, -1>>;
type res3 = Call2<Numbers.Compare, 2, 2>;
type res3 = Call<Numbers.Compare, 2, 2>;
// ^?
type test3 = Expect<Equal<res3, 0>>;
});
@@ -266,7 +266,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.Compare<2, 3>>;
type res1 = Call<Numbers.Compare<2, 3>>;
// ^?
type test1 = Expect<Equal<res1, -1>>;
});
@@ -274,15 +274,15 @@ describe("Numbers", () => {
describe("LessThan", () => {
it("can be called without any pre-filled arguments", () => {
type res1 = Call2<Numbers.LessThan, 3, 2>;
type res1 = Call<Numbers.LessThan, 3, 2>;
// ^?
type test1 = Expect<Equal<res1, false>>;
type res2 = Call2<Numbers.LessThan, 2, 3>;
type res2 = Call<Numbers.LessThan, 2, 3>;
// ^?
type test2 = Expect<Equal<res2, true>>;
type res3 = Call2<Numbers.LessThan, 2, 2>;
type res3 = Call<Numbers.LessThan, 2, 2>;
// ^?
type test3 = Expect<Equal<res3, false>>;
});
@@ -294,7 +294,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.LessThan<2, 3>>;
type res1 = Call<Numbers.LessThan<2, 3>>;
// ^?
type test1 = Expect<Equal<res1, true>>;
});
@@ -302,15 +302,15 @@ describe("Numbers", () => {
describe("LessThanOrEqual", () => {
it("can be called without any pre-filled arguments", () => {
type res1 = Call2<Numbers.LessThanOrEqual, 3, 2>;
type res1 = Call<Numbers.LessThanOrEqual, 3, 2>;
// ^?
type test1 = Expect<Equal<res1, false>>;
type res2 = Call2<Numbers.LessThanOrEqual, 2, 3>;
type res2 = Call<Numbers.LessThanOrEqual, 2, 3>;
// ^?
type test2 = Expect<Equal<res2, true>>;
type res3 = Call2<Numbers.LessThanOrEqual, 2, 2>;
type res3 = Call<Numbers.LessThanOrEqual, 2, 2>;
// ^?
type test3 = Expect<Equal<res3, true>>;
});
@@ -322,7 +322,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.LessThanOrEqual<2, 3>>;
type res1 = Call<Numbers.LessThanOrEqual<2, 3>>;
// ^?
type test1 = Expect<Equal<res1, true>>;
});
@@ -330,15 +330,15 @@ describe("Numbers", () => {
describe("GreaterThan", () => {
it("can be called without any pre-filled arguments", () => {
type res1 = Call2<Numbers.GreaterThan, 3, 2>;
type res1 = Call<Numbers.GreaterThan, 3, 2>;
// ^?
type test1 = Expect<Equal<res1, true>>;
type res2 = Call2<Numbers.GreaterThan, 2, 3>;
type res2 = Call<Numbers.GreaterThan, 2, 3>;
// ^?
type test2 = Expect<Equal<res2, false>>;
type res3 = Call2<Numbers.GreaterThan, 2, 2>;
type res3 = Call<Numbers.GreaterThan, 2, 2>;
// ^?
type test3 = Expect<Equal<res3, false>>;
});
@@ -350,13 +350,13 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.GreaterThan<2, 3>>;
type res1 = Call<Numbers.GreaterThan<2, 3>>;
// ^?
type test1 = Expect<Equal<res1, false>>;
});
it("should reverse it's function arguments when partial applied", () => {
type res4 = Eval<Numbers.GreaterThan<1, 2>>;
type res4 = Call<Numbers.GreaterThan<1, 2>>;
type test4 = Expect<Equal<res4, false>>;
type res5 = Call<Numbers.GreaterThan<_, 2>, 1>;
@@ -375,15 +375,15 @@ describe("Numbers", () => {
describe("GreaterThanOrEqual", () => {
it("can be called without any pre-filled arguments", () => {
type res1 = Call2<Numbers.GreaterThanOrEqual, 3, 2>;
type res1 = Call<Numbers.GreaterThanOrEqual, 3, 2>;
// ^?
type test1 = Expect<Equal<res1, true>>;
type res2 = Call2<Numbers.GreaterThanOrEqual, 2, 3>;
type res2 = Call<Numbers.GreaterThanOrEqual, 2, 3>;
// ^?
type test2 = Expect<Equal<res2, false>>;
type res3 = Call2<Numbers.GreaterThanOrEqual, 2, 2>;
type res3 = Call<Numbers.GreaterThanOrEqual, 2, 2>;
// ^?
type test3 = Expect<Equal<res3, true>>;
});
@@ -395,7 +395,7 @@ describe("Numbers", () => {
});
it("can be called with 1 pre-filled arguments", () => {
type res1 = Eval<Numbers.GreaterThanOrEqual<2, 3>>;
type res1 = Call<Numbers.GreaterThanOrEqual<2, 3>>;
// ^?
type test1 = Expect<Equal<res1, false>>;
});

View File

@@ -5,15 +5,12 @@ import {
arg1,
arg2,
arg3,
Call,
ComposeLeft,
Constant,
Eval,
Fn,
Call,
Pipe,
_,
} from "../src/internals/core/Core";
import { Functions } from "../src/internals/functions/Functions";
import { Strings } from "../src/internals/strings/Strings";
import { Objects } from "../src/internals/objects/Objects";
import { Tuples } from "../src/internals/tuples/Tuples";
@@ -198,7 +195,7 @@ describe("Objects", () => {
{ a: 1; b: true }
>;
type tes1 = Expect<Equal<res1, { readonly a: 1; readonly b: true }>>;
type res2 = Eval<
type res2 = Call<
// ^?
Objects.Readonly<{ a: 1; b: true }>
>;
@@ -212,7 +209,7 @@ describe("Objects", () => {
{ a?: 1; b?: true }
>;
type tes1 = Expect<Equal<res1, { a: 1; b: true }>>;
type res2 = Eval<
type res2 = Call<
// ^?
Objects.Required<{ a?: 1; b?: true }>
>;
@@ -226,7 +223,7 @@ describe("Objects", () => {
{ a: 1; b: true }
>;
type tes1 = Expect<Equal<res1, { a?: 1; b?: true }>>;
type res2 = Eval<
type res2 = Call<
// ^?
Objects.Partial<{ a: 1; b: true }>
>;
@@ -459,7 +456,7 @@ describe("Objects", () => {
});
it("can be called with 2 pre-filled arguments", () => {
type res1 = Eval<Objects.Assign<{ a: string }, { b: number }>>;
type res1 = Call<Objects.Assign<{ a: string }, { b: number }>>;
// ^?
type test1 = Expect<Equal<res1, { a: string; b: number }>>;
});
@@ -586,7 +583,7 @@ describe("Objects", () => {
describe("Get", () => {
it("should retrieve a deep property", () => {
type res1 = Eval<
type res1 = Call<
// ^?
Objects.Get<"a.b.c.d", { a: { b: { c: { d: string } } } }>
>;
@@ -605,7 +602,7 @@ describe("Objects", () => {
| { a: { b: string | { c: { d: string } } } }
| { a: { b: { c: { d: number } } } };
type res1 = Eval<Objects.Get<"a.b.c.d", input>>;
type res1 = Call<Objects.Get<"a.b.c.d", input>>;
// ^?
type test1 = Expect<Equal<res1, string | number | undefined>>;
@@ -615,19 +612,19 @@ describe("Objects", () => {
});
it("should support arrays", () => {
type res1 = Eval<Objects.Get<"a.b[0].d", { a: { b: { d: string }[] } }>>;
type res1 = Call<Objects.Get<"a.b[0].d", { a: { b: { d: string }[] } }>>;
// ^?
type test1 = Expect<Equal<res1, string>>;
});
it("should support tuples", () => {
type input = { a: { b: [{ d: string }, "hello"] } };
type res1 = Eval<Objects.Get<"a.b[0].d", input>>;
type res1 = Call<Objects.Get<"a.b[0].d", input>>;
// ^?
type test1 = Expect<Equal<res1, string>>;
type res2 = Eval<Objects.Get<"a.b[1]", input>>;
type res2 = Call<Objects.Get<"a.b[1]", input>>;
// ^?
type test2 = Expect<Equal<res2, "hello">>;
});
@@ -640,7 +637,7 @@ describe("Objects", () => {
number
>;
type tes1 = Expect<Equal<res1, { a: number; b: number }>>;
type res2 = Eval<
type res2 = Call<
// ^?
Objects.Record<"a" | "b", number>
>;

View File

@@ -57,7 +57,7 @@ describe("Reselect", () => {
* ```
*/
interface GetUnknownPadding<argsList extends any[][]> extends H.Fn {
return: H.Eval<
return: H.Call<
H.Tuples.Map<
H.ComposeLeft<
[

View File

@@ -1,26 +1,16 @@
import {
_,
Call,
Call2,
Strings,
Functions,
Pipe,
Tuples,
Unions,
Objects,
} from "../src/index";
import { Apply, arg0, Compose, Eval } from "../src/internals/core/Core";
import { _, $, Numbers, Strings, Tuples } from "../src/index";
import { Compose } from "../src/internals/core/Core";
import { Equal, Expect } from "../src/internals/helpers";
describe("Strings", () => {
it("Length", () => {
type res1 = Call<Strings.Length, "">;
type res1 = $<Strings.Length, "">;
// ^?
type test1 = Expect<Equal<res1, 0>>;
type res2 = Call<Strings.Length, "123">;
type res2 = $<Strings.Length, "123">;
// ^?
type test2 = Expect<Equal<res2, 3>>;
type res3 = Call<
type res3 = $<
// ^?
Compose<[Strings.Length, Strings.Repeat<1001>]>,
"a"
@@ -29,67 +19,67 @@ describe("Strings", () => {
});
it("TrimLeft", () => {
type res1 = Call<Strings.TrimLeft, " abc ">;
type res1 = $<Strings.TrimLeft, " abc ">;
// ^?
type test1 = Expect<Equal<res1, "abc ">>;
type res2 = Call<Strings.TrimLeft<"0">, "0001000">;
type res2 = $<Strings.TrimLeft<"0">, "0001000">;
// ^?
type test2 = Expect<Equal<res2, "1000">>;
});
it("TrimRight", () => {
type res1 = Call<Strings.TrimRight, " abc ">;
type res1 = $<Strings.TrimRight, " abc ">;
// ^?
type test1 = Expect<Equal<res1, " abc">>;
type res2 = Call<Strings.TrimRight<"0">, "0001000">;
type res2 = $<Strings.TrimRight<"0">, "0001000">;
// ^?
type test2 = Expect<Equal<res2, "0001">>;
});
it("Trim", () => {
type res1 = Call<Strings.Trim, " abc ">;
type res1 = $<Strings.Trim, " abc ">;
// ^?
type test1 = Expect<Equal<res1, "abc">>;
type res2 = Call<Strings.Trim<"0">, "0001000">;
type res2 = $<Strings.Trim<"0">, "0001000">;
// ^?
type test2 = Expect<Equal<res2, "1">>;
});
describe("Replace", () => {
it("replaces single letters", () => {
type res1 = Call<Strings.Replace<"a", "b">, "abc">;
type res1 = $<Strings.Replace<"a", "b">, "abc">;
// ^?
type test1 = Expect<Equal<res1, "bbc">>;
});
it("is identity on empty strings", () => {
type res2 = Call<Strings.Replace<"a", "b">, "">;
type res2 = $<Strings.Replace<"a", "b">, "">;
// ^?
type test2 = Expect<Equal<res2, "">>;
});
it("replacing by empty string", () => {
type res3 = Call<Strings.Replace<"a", "">, "abc">;
type res3 = $<Strings.Replace<"a", "">, "abc">;
// ^?
type test3 = Expect<Equal<res3, "bc">>;
});
it("supports multi char strings", () => {
type res4 = Call<Strings.Replace<"hello", "hi!">, "hello world!">;
type res4 = $<Strings.Replace<"hello", "hi!">, "hello world!">;
// ^?
type test4 = Expect<Equal<res4, "hi! world!">>;
type res5 = Call<Strings.Replace<"many", "more">, "many more than many">;
type res5 = $<Strings.Replace<"many", "more">, "many more than many">;
// ^?
type test5 = Expect<Equal<res5, "more more than more">>;
});
it("supports union types", () => {
type res6 = Call<Strings.Replace<"a" | "b", "c">, "abc">;
type res6 = $<Strings.Replace<"a" | "b", "c">, "abc">;
// ^?
type test6 = Expect<Equal<res6, "ccc">>;
type res4 = Call<
type res4 = $<
// ^?
Strings.Replace<"hello" | "hi", "sup">,
"hello world! hi!"
@@ -99,244 +89,244 @@ describe("Strings", () => {
});
it("Slice", () => {
type res1 = Call<Strings.Slice<1, 3>, "123">;
type res1 = $<Strings.Slice<1, 3>, "123">;
// ^?
type test1 = Expect<Equal<res1, "23">>;
type res2 = Call<Strings.Slice<0, 3>, "123">;
type res2 = $<Strings.Slice<0, 3>, "123">;
// ^?
type test2 = Expect<Equal<res2, "123">>;
type res3 = Call<Strings.Slice<1, 4>, "123">;
type res3 = $<Strings.Slice<1, 4>, "123">;
// ^?
type test3 = Expect<Equal<res3, "23">>;
type res4 = Call<Strings.Slice<1, 1>, "123">;
type res4 = $<Strings.Slice<1, 1>, "123">;
// ^?
type test4 = Expect<Equal<res4, "">>;
});
it("Split", () => {
type res1 = Call<Strings.Split<".">, "1.2.3">;
type res1 = $<Strings.Split<".">, "1.2.3">;
// ^?
type test1 = Expect<Equal<res1, ["1", "2", "3"]>>;
type res2 = Call<Strings.Split<"">, "123">;
type res2 = $<Strings.Split<"">, "123">;
// ^?
type test2 = Expect<Equal<res2, ["1", "2", "3"]>>;
type res3 = Call<Strings.Split<"">, "">;
type res3 = $<Strings.Split<"">, "">;
// ^?
type test3 = Expect<Equal<res3, []>>;
type res4 = Call<Strings.Split<"--" | ".">, "1--2-3.4..5">;
type res4 = $<Strings.Split<"--" | ".">, "1--2-3.4..5">;
// ^?
type test4 = Expect<Equal<res4, ["1", "2-3", "4", "5"]>>;
});
it("Repeat", () => {
type res1 = Call<Strings.Repeat<3>, "a">;
type res1 = $<Strings.Repeat<3>, "a">;
// ^?
type test1 = Expect<Equal<res1, "aaa">>;
type res2 = Call<Strings.Repeat<0>, "a">;
type res2 = $<Strings.Repeat<0>, "a">;
// ^?
type test2 = Expect<Equal<res2, "">>;
type res3 = Call<Strings.Repeat<1>, "a">;
type res3 = $<Strings.Repeat<1>, "a">;
// ^?
type test3 = Expect<Equal<res3, "a">>;
type res4 = Call<Strings.Repeat<2>, "hello!">;
type res4 = $<Strings.Repeat<2>, "hello!">;
// ^?
type test4 = Expect<Equal<res4, "hello!hello!">>;
});
it("StartsWith", () => {
type res1 = Call<Strings.StartsWith<"hello">, "hello world">;
type res1 = $<Strings.StartsWith<"hello">, "hello world">;
// ^?
type test1 = Expect<Equal<res1, true>>;
type res2 = Call<Strings.StartsWith<"hello">, "world hello">;
type res2 = $<Strings.StartsWith<"hello">, "world hello">;
// ^?
type test2 = Expect<Equal<res2, false>>;
type res3 = Call<Strings.StartsWith<"">, "hello world">;
type res3 = $<Strings.StartsWith<"">, "hello world">;
// ^?
type test3 = Expect<Equal<res3, true>>;
type res4 = Call<Strings.StartsWith<"">, "">;
type res4 = $<Strings.StartsWith<"">, "">;
// ^?
type test4 = Expect<Equal<res4, true>>;
});
it("EndsWith", () => {
type res1 = Call<Strings.EndsWith<"world">, "hello world">;
type res1 = $<Strings.EndsWith<"world">, "hello world">;
// ^?
type test1 = Expect<Equal<res1, true>>;
type res2 = Call<Strings.EndsWith<"world">, "world hello">;
type res2 = $<Strings.EndsWith<"world">, "world hello">;
// ^?
type test2 = Expect<Equal<res2, false>>;
type res3 = Call<Strings.EndsWith<"">, "hello world">;
type res3 = $<Strings.EndsWith<"">, "hello world">;
// ^?
type test3 = Expect<Equal<res3, true>>;
type res4 = Call<Strings.EndsWith<"">, "">;
type res4 = $<Strings.EndsWith<"">, "">;
// ^?
type test4 = Expect<Equal<res4, true>>;
});
it("ToTuple", () => {
type res1 = Call<Strings.ToTuple, "abc">;
type res1 = $<Strings.ToTuple, "abc">;
// ^?
type test1 = Expect<Equal<res1, ["a", "b", "c"]>>;
type res2 = Call<Strings.ToTuple, "">;
type res2 = $<Strings.ToTuple, "">;
// ^?
type test2 = Expect<Equal<res2, []>>;
});
it("ToNumber", () => {
type res1 = Call<Strings.ToNumber, "11">;
type res1 = $<Strings.ToNumber, "11">;
// ^?
type test1 = Expect<Equal<res1, 11>>;
});
it("ToString", () => {
type res1 = Call<Strings.ToString, 11>;
type res1 = $<Strings.ToString, 11>;
// ^?
type test1 = Expect<Equal<res1, "11">>;
});
it("Prepend", () => {
type res1 = Call<Strings.Prepend<"1 ">, "abc">;
type res1 = $<Strings.Prepend<"1 ">, "abc">;
// ^?
type test1 = Expect<Equal<res1, "1 abc">>;
});
it("Append", () => {
type res1 = Call<Strings.Append<" 1">, "abc">;
type res1 = $<Strings.Append<" 1">, "abc">;
// ^?
type test1 = Expect<Equal<res1, "abc 1">>;
});
it("Uppercase", () => {
type res1 = Call<Strings.Uppercase, "abc">;
type res1 = $<Strings.Uppercase, "abc">;
// ^?
type test1 = Expect<Equal<res1, "ABC">>;
});
it("Lowercase", () => {
type res1 = Call<Strings.Lowercase, "ABC">;
type res1 = $<Strings.Lowercase, "ABC">;
// ^?
type test1 = Expect<Equal<res1, "abc">>;
});
it("Capitalize", () => {
type res1 = Call<Strings.Capitalize, "abc">;
type res1 = $<Strings.Capitalize, "abc">;
// ^?
type test1 = Expect<Equal<res1, "Abc">>;
});
it("Uncapitalize", () => {
type res1 = Call<Strings.Uncapitalize, "ABC">;
type res1 = $<Strings.Uncapitalize, "ABC">;
// ^?
type test1 = Expect<Equal<res1, "aBC">>;
});
it("SnakeCase", () => {
type res1 = Call<Strings.SnakeCase, "helloWorldYo">;
type res1 = $<Strings.SnakeCase, "helloWorldYo">;
// ^?
type test1 = Expect<Equal<res1, "hello_world_yo">>;
type res2 = Call<Strings.SnakeCase, "HelloWorldYo">;
type res2 = $<Strings.SnakeCase, "HelloWorldYo">;
// ^?
type test2 = Expect<Equal<res2, "hello_world_yo">>;
});
it("KebabCase", () => {
type res1 = Call<Strings.KebabCase, "helloWorldYo">;
type res1 = $<Strings.KebabCase, "helloWorldYo">;
// ^?
type test1 = Expect<Equal<res1, "hello-world-yo">>;
type res2 = Call<Strings.KebabCase, "HelloWorldYo">;
type res2 = $<Strings.KebabCase, "HelloWorldYo">;
// ^?
type test2 = Expect<Equal<res2, "hello-world-yo">>;
});
it("CamelCase", () => {
type res1 = Call<Strings.CamelCase, "hello_world_yo">;
type res1 = $<Strings.CamelCase, "hello_world_yo">;
// ^?
type test1 = Expect<Equal<res1, "helloWorldYo">>;
});
it("Compare", () => {
type res1 = Call<Strings.Compare<"a">, "a">;
type res1 = $<Strings.Compare<"a">, "a">;
// ^?
type test1 = Expect<Equal<res1, 0>>;
type res2 = Call<Strings.Compare<"a">, "b">;
type res2 = $<Strings.Compare<"a">, "b">;
// ^?
type test2 = Expect<Equal<res2, 1>>;
type res3 = Call<Strings.Compare<"a", _>, "b">;
type res3 = $<Strings.Compare<"a", _>, "b">;
// ^?
type test3 = Expect<Equal<res3, -1>>;
type res4 = Call<Strings.Compare<"b">, "a">;
type res4 = $<Strings.Compare<"b">, "a">;
// ^?
type test4 = Expect<Equal<res4, -1>>;
type res5 = Call2<Strings.Compare, "ab", "b">;
type res5 = $<Strings.Compare, "ab", "b">;
// ^?
type test5 = Expect<Equal<res5, -1>>;
type res6 = Call2<Strings.Compare, "b", "ab">;
type res6 = $<Strings.Compare, "b", "ab">;
// ^?
type test6 = Expect<Equal<res6, 1>>;
type res7 = Call2<Strings.Compare, "ab", "ab">;
type res7 = $<Strings.Compare, "ab", "ab">;
// ^?
type test7 = Expect<Equal<res7, 0>>;
type res8 = Call2<Strings.Compare, "ab", "ac">;
type res8 = $<Strings.Compare, "ab", "ac">;
// ^?
type test8 = Expect<Equal<res8, -1>>;
});
it("LessThan", () => {
type res1 = Call<Strings.LessThan<"a">, "b">;
type res1 = $<Strings.LessThan<"a">, "b">;
// ^?
type test1 = Expect<Equal<res1, false>>;
type res2 = Call<Strings.LessThan<"b">, "a">;
type res2 = $<Strings.LessThan<"b">, "a">;
// ^?
type test2 = Expect<Equal<res2, true>>;
type res3 = Call<Strings.LessThan<"a">, "a">;
type res3 = $<Strings.LessThan<"a">, "a">;
// ^?
type test3 = Expect<Equal<res3, false>>;
type res4 = Call2<Strings.LessThan, "a", "aa">;
type res4 = $<Strings.LessThan, "a", "aa">;
// ^?
type test4 = Expect<Equal<res4, true>>;
});
it("LessThanOrEqual", () => {
type res1 = Call<Strings.LessThanOrEqual<"a">, "b">;
type res1 = $<Strings.LessThanOrEqual<"a">, "b">;
// ^?
type test1 = Expect<Equal<res1, false>>;
type res2 = Call<Strings.LessThanOrEqual<"b">, "a">;
type res2 = $<Strings.LessThanOrEqual<"b">, "a">;
// ^?
type test2 = Expect<Equal<res2, true>>;
type res3 = Call<Strings.LessThanOrEqual<"a">, "a">;
type res3 = $<Strings.LessThanOrEqual<"a">, "a">;
// ^?
type test3 = Expect<Equal<res3, true>>;
type res4 = Call2<Strings.LessThanOrEqual, "a", "aa">;
type res4 = $<Strings.LessThanOrEqual, "a", "aa">;
// ^?
type test4 = Expect<Equal<res4, true>>;
});
it("GreaterThan", () => {
type res1 = Call<Strings.GreaterThan<"a">, "b">;
type res1 = $<Strings.GreaterThan<"a">, "b">;
// ^?
type test1 = Expect<Equal<res1, true>>;
type res2 = Call<Strings.GreaterThan<"b">, "a">;
type res2 = $<Strings.GreaterThan<"b">, "a">;
// ^?
type test2 = Expect<Equal<res2, false>>;
type res3 = Call<Strings.GreaterThan<"a">, "a">;
type res3 = $<Strings.GreaterThan<"a">, "a">;
// ^?
type test3 = Expect<Equal<res3, false>>;
type res4 = Call2<Strings.GreaterThan, "a", "aa">;
type res4 = $<Strings.GreaterThan, "a", "aa">;
// ^?
type test4 = Expect<Equal<res4, false>>;
});
it("GreaterThanOrEqual", () => {
type res1 = Call<Strings.GreaterThanOrEqual<"a">, "b">;
type res1 = $<Strings.GreaterThanOrEqual<"a">, "b">;
// ^?
type test1 = Expect<Equal<res1, true>>;
type res2 = Call<Strings.GreaterThanOrEqual<"b">, "a">;
type res2 = $<Strings.GreaterThanOrEqual<"b">, "a">;
// ^?
type test2 = Expect<Equal<res2, false>>;
type res3 = Call<Strings.GreaterThanOrEqual<"a">, "a">;
type res3 = $<Strings.GreaterThanOrEqual<"a">, "a">;
// ^?
type test3 = Expect<Equal<res3, true>>;
type res4 = Call2<Strings.GreaterThanOrEqual, "a", "aa">;
type res4 = $<Strings.GreaterThanOrEqual, "a", "aa">;
// ^?
type test4 = Expect<Equal<res4, false>>;
});

View File

@@ -1,5 +1,5 @@
import { Booleans } from "../src/internals/booleans/Booleans";
import { Call, Call2, Eval, Fn, Pipe, _ } from "../src/internals/core/Core";
import { Call, Fn, Pipe, _ } from "../src/internals/core/Core";
import { Equal, Expect } from "../src/internals/helpers";
import { Numbers } from "../src/internals/numbers/Numbers";
import { Objects } from "../src/internals/objects/Objects";
@@ -12,7 +12,7 @@ describe("Tuples", () => {
// ^?
type tes1 = Expect<Equal<res1, 1>>;
type res2 = Eval<Tuples.Head<[1, 2, 3]>>;
type res2 = Call<Tuples.Head<[1, 2, 3]>>;
// ^?
type tes2 = Expect<Equal<res2, 1>>;
});
@@ -22,7 +22,7 @@ describe("Tuples", () => {
// ^?
type tes1 = Expect<Equal<res1, [2, 3]>>;
type res2 = Eval<Tuples.Tail<[1, 2, 3]>>;
type res2 = Call<Tuples.Tail<[1, 2, 3]>>;
// ^?
type tes2 = Expect<Equal<res2, [2, 3]>>;
});
@@ -32,7 +32,7 @@ describe("Tuples", () => {
// ^?
type tes1 = Expect<Equal<res1, 3>>;
type res2 = Eval<Tuples.Last<[1, 2, 3]>>;
type res2 = Call<Tuples.Last<[1, 2, 3]>>;
// ^?
type tes2 = Expect<Equal<res2, 3>>;
});
@@ -48,7 +48,7 @@ describe("Tuples", () => {
Equal<res1, ["number is 1", "number is 2", "number is 3"]>
>;
type res2 = Eval<Tuples.Map<ToPhrase, [1, 2, 3]>>;
type res2 = Call<Tuples.Map<ToPhrase, [1, 2, 3]>>;
// ^?
type tes2 = Expect<
Equal<res2, ["number is 1", "number is 2", "number is 3"]>
@@ -68,11 +68,11 @@ describe("Tuples", () => {
// ^?
type tes2 = Expect<Equal<res2, [1, 2, 3]>>;
type res3 = Eval<Tuples.Filter<IsNumber, [1, 2, "oops", 3]>>;
type res3 = Call<Tuples.Filter<IsNumber, [1, 2, "oops", 3]>>;
// ^?
type tes3 = Expect<Equal<res3, [1, 2, 3]>>;
type res4 = Eval<Tuples.Filter<IsNumber, readonly [1, 2, "oops", 3]>>;
type res4 = Call<Tuples.Filter<IsNumber, readonly [1, 2, "oops", 3]>>;
// ^?
type tes4 = Expect<Equal<res4, [1, 2, 3]>>;
});
@@ -88,7 +88,7 @@ describe("Tuples", () => {
// ^?
type tes1 = Expect<Equal<res1, [[1], [2], [3]]>>;
type res2 = Eval<Tuples.Reduce<ToUnaryTupleArray, [], [1, 2, 3]>>;
type res2 = Call<Tuples.Reduce<ToUnaryTupleArray, [], [1, 2, 3]>>;
// ^?
type tes2 = Expect<Equal<res2, [[1], [2], [3]]>>;
});
@@ -107,7 +107,7 @@ describe("Tuples", () => {
>;
type tes1 = Expect<Equal<res1, [[3], [2], [1]]>>;
type res2 = Eval<Tuples.ReduceRight<ToUnaryTupleArray, [], [1, 2, 3]>>;
type res2 = Call<Tuples.ReduceRight<ToUnaryTupleArray, [], [1, 2, 3]>>;
// ^?
type tes2 = Expect<Equal<res2, [[3], [2], [1]]>>;
});
@@ -121,7 +121,7 @@ describe("Tuples", () => {
// ^?
type tes1 = Expect<Equal<res1, [1, 1, 2, 2, 3, 3]>>;
type res2 = Eval<Tuples.FlatMap<Duplicate, [1, 2, 3]>>;
type res2 = Call<Tuples.FlatMap<Duplicate, [1, 2, 3]>>;
// ^?
type tes2 = Expect<Equal<res2, [1, 1, 2, 2, 3, 3]>>;
});
@@ -143,7 +143,7 @@ describe("Tuples", () => {
// ^?
type tes2 = Expect<Equal<res2, "b">>;
type res3 = Eval<Tuples.Find<IsSecond, ["a", "b", "c", 2, "d"]>>;
type res3 = Call<Tuples.Find<IsSecond, ["a", "b", "c", 2, "d"]>>;
// ^?
type tes3 = Expect<Equal<res3, "b">>;
});
@@ -157,7 +157,7 @@ describe("Tuples", () => {
// ^?
type tes2 = Expect<Equal<res2, ["c", 2, "d"]>>;
type res3 = Eval<Tuples.Drop<2, ["a", "b", "c", 2, "d"]>>;
type res3 = Call<Tuples.Drop<2, ["a", "b", "c", 2, "d"]>>;
// ^?
type tes3 = Expect<Equal<res3, ["c", 2, "d"]>>;
});
@@ -171,7 +171,7 @@ describe("Tuples", () => {
// ^?
type tes2 = Expect<Equal<res2, ["a", "b"]>>;
type res3 = Eval<Tuples.Take<2, ["a", "b", "c", 2, "d"]>>;
type res3 = Call<Tuples.Take<2, ["a", "b", "c", 2, "d"]>>;
// ^?
type tes3 = Expect<Equal<res3, ["a", "b"]>>;
});
@@ -191,7 +191,7 @@ describe("Tuples", () => {
>;
type tes2 = Expect<Equal<res2, [1, 2]>>;
type res3 = Eval<
type res3 = Call<
// ^?
Tuples.TakeWhile<
Booleans.Extends<_, number>,
@@ -271,7 +271,7 @@ describe("Tuples", () => {
// ^?
type test1 = Expect<Equal<res1, [1, 2, 3, 4]>>;
type res2 = Eval<Tuples.Append<4, [1, 2, 3]>>;
type res2 = Call<Tuples.Append<4, [1, 2, 3]>>;
// ^?
type test2 = Expect<Equal<res2, [1, 2, 3, 4]>>;
});
@@ -281,7 +281,7 @@ describe("Tuples", () => {
// ^?
type test1 = Expect<Equal<res1, [0, 1, 2, 3]>>;
type res2 = Eval<Tuples.Prepend<0, [1, 2, 3]>>;
type res2 = Call<Tuples.Prepend<0, [1, 2, 3]>>;
// ^?
type test2 = Expect<Equal<res2, [0, 1, 2, 3]>>;
});
@@ -291,7 +291,7 @@ describe("Tuples", () => {
// ^?
type test1 = Expect<Equal<res1, [0, 1, 2, 3]>>;
type res2 = Eval<Tuples.Concat<[1, 2], [3]>>;
type res2 = Call<Tuples.Concat<[1, 2], [3]>>;
// ^?
type test2 = Expect<Equal<res2, [1, 2, 3]>>;
});
@@ -313,14 +313,14 @@ describe("Tuples", () => {
});
it("At", () => {
type res1 = Eval<
type res1 = Call<
// ^?
Tuples.At<2, [1, "a", 2, "b", 3, "c"]>
>;
type test1 = Expect<Equal<res1, 2>>;
// check out of bounds
type res2 = Eval<
type res2 = Call<
// ^?
Tuples.At<6, [1, "a", 2, "b", 3, "c"]>
>;
@@ -328,7 +328,7 @@ describe("Tuples", () => {
});
it("IsEmpty", () => {
type res1 = Eval<
type res1 = Call<
// ^?
Tuples.IsEmpty<[1, "a", 2, "b", 3, "c"]>
>;
@@ -341,7 +341,7 @@ describe("Tuples", () => {
>;
type test2 = Expect<Equal<res2, true>>;
type res3 = Eval<
type res3 = Call<
// ^?
Tuples.IsEmpty<[]>
>;
@@ -349,7 +349,7 @@ describe("Tuples", () => {
});
it("Zip", () => {
type x = Eval<Tuples.Zip<[1, 2, 3]>>;
type x = Call<Tuples.Zip<[1, 2, 3]>>;
// ^?
type res1 = Call<
@@ -359,7 +359,7 @@ describe("Tuples", () => {
>;
type test1 = Expect<Equal<res1, [[1, "a"], [2, "b"], [3, "c"]]>>;
type res2 = Call2<
type res2 = Call<
// ^?
Tuples.Zip,
[1, 2, 3],
@@ -367,13 +367,13 @@ describe("Tuples", () => {
>;
type test2 = Expect<Equal<res2, [[1, "a"], [2, "b"], [3, "c"]]>>;
type res3 = Eval<
type res3 = Call<
// ^?
Tuples.Zip<[1, 2, 3], ["a", "b", "c"]>
>;
type test3 = Expect<Equal<res3, [[1, "a"], [2, "b"], [3, "c"]]>>;
type res4 = Eval<
type res4 = Call<
// ^?
Tuples.Zip<[1, 2, 3], ["a", "b", "c"], [true, false, true]>
>;
@@ -383,7 +383,7 @@ describe("Tuples", () => {
});
it("ZipWith", () => {
type res1 = Call2<
type res1 = Call<
// ^?
Tuples.ZipWith<Numbers.Add>,
[1, 2, 3],
@@ -391,7 +391,7 @@ describe("Tuples", () => {
>;
type test1 = Expect<Equal<res1, [5, 7, 9]>>;
type res2 = Eval<
type res2 = Call<
// ^?
Tuples.ZipWith<Numbers.Add, [1, 2, 3], [4, 5, 6]>
>;
@@ -452,45 +452,45 @@ describe("Tuples", () => {
// ^?
type test1 = Expect<Equal<res1, [5, 6, 7, 8, 9, 10]>>;
type res3 = Eval<Tuples.Range<-2, 2>>;
type res3 = Call<Tuples.Range<-2, 2>>;
// ^?
type test3 = Expect<Equal<res3, [-2, -1, 0, 1, 2]>>;
type res4 = Eval<Tuples.Range<-5, -2>>;
type res4 = Call<Tuples.Range<-5, -2>>;
// ^?
type test4 = Expect<Equal<res4, [-5, -4, -3, -2]>>;
});
it("Min", () => {
type res1 = Eval<Tuples.Min<[1, 2, 3]>>;
type res1 = Call<Tuples.Min<[1, 2, 3]>>;
// ^?
type test1 = Expect<Equal<res1, 1>>;
type res2 = Eval<Tuples.Min<[-1, -2, -3]>>;
type res2 = Call<Tuples.Min<[-1, -2, -3]>>;
// ^?
type test2 = Expect<Equal<res2, -3>>;
type res3 = Eval<Tuples.Min<[]>>;
type res3 = Call<Tuples.Min<[]>>;
// ^?
type test3 = Expect<Equal<res3, never>>;
});
it("Max", () => {
type res1 = Eval<Tuples.Max<[1, 2, 3]>>;
type res1 = Call<Tuples.Max<[1, 2, 3]>>;
// ^?
type test1 = Expect<Equal<res1, 3>>;
type res2 = Eval<Tuples.Max<[-1, -2, -3]>>;
type res2 = Call<Tuples.Max<[-1, -2, -3]>>;
// ^?
type test2 = Expect<Equal<res2, -1>>;
type res3 = Eval<Tuples.Max<[]>>;
type res3 = Call<Tuples.Max<[]>>;
// ^?
type test3 = Expect<Equal<res3, never>>;
});
it("ToUnion", () => {
type res1 = Eval<Tuples.ToUnion<[1, "a", 2, "b", 3, "c"]>>;
type res1 = Call<Tuples.ToUnion<[1, "a", 2, "b", 3, "c"]>>;
// ^?
type test1 = Expect<Equal<res1, 1 | "a" | 2 | "b" | 3 | "c">>;
});

View File

@@ -1,4 +1,4 @@
import { Pipe, Fn, B, U, F, Eval, Call, Unions, _ } from "../src/index";
import { Pipe, Fn, B, U, F, Call, Unions, _ } from "../src/index";
import { Compose } from "../src/internals/core/Core";
import { Equal, Expect, Extends } from "../src/internals/helpers";
@@ -13,7 +13,7 @@ describe("Unions", () => {
type res1 = Pipe<"a" | 1 | null | undefined, [U.NonNullable]>;
// ^?
type tes1 = Expect<Equal<res1, "a" | 1>>;
type res2 = Eval<Unions.NonNullable<"a" | 1 | null | undefined>>;
type res2 = Call<Unions.NonNullable<"a" | 1 | null | undefined>>;
// ^?
type tes2 = Expect<Equal<res2, "a" | 1>>;
type res3 = Call<Unions.NonNullable, "a" | 1 | null | undefined>;
@@ -50,7 +50,7 @@ describe("Unions", () => {
// ^?
type tes1 = Expect<Equal<res1, ["a"] | ["b"] | ["c"]>>;
type res2 = Eval<U.Map<ToTuple, "a" | "b" | "c">>;
type res2 = Call<U.Map<ToTuple, "a" | "b" | "c">>;
// ^?
type tes2 = Expect<Equal<res2, ["a"] | ["b"] | ["c"]>>;
});
@@ -64,11 +64,11 @@ describe("Unions", () => {
// ^?
type test1 = Expect<Equal<res1, 5 | 6 | 7 | 8 | 9 | 10>>;
type res3 = Eval<Unions.Range<-2, 2>>;
type res3 = Call<Unions.Range<-2, 2>>;
// ^?
type test3 = Expect<Equal<res3, -2 | -1 | 0 | 1 | 2>>;
type res4 = Eval<Unions.Range<-5, -2>>;
type res4 = Call<Unions.Range<-5, -2>>;
// ^?
type test4 = Expect<Equal<res4, -5 | -4 | -3 | -2>>;
});