Comparing version 1.0.5 to 1.0.6
@@ -33,7 +33,8 @@ declare const rawArgs: unique symbol; | ||
export type _ = "@hotscript/placeholder"; | ||
export type arg<Index extends number, Constraint = unknown> = { | ||
tag: "@hotscript/arg"; | ||
index: Index; | ||
constraint: Constraint; | ||
}; | ||
export interface arg<Index extends number, Constraint = unknown> extends Fn { | ||
return: this["args"][Index] extends infer arg extends Constraint ? arg : never; | ||
} | ||
export interface args<Constraint extends unknown[] = unknown[]> extends Fn { | ||
return: this["args"] extends infer args extends Constraint ? args : never; | ||
} | ||
export type arg0<Constraint = unknown> = arg<0, Constraint>; | ||
@@ -40,0 +41,0 @@ export type arg1<Constraint = unknown> = arg<1, Constraint>; |
@@ -143,1 +143,3 @@ import type { ToString, Digit, DigitNumber, ToDigitNumber, Sign, Num } from "./utils"; | ||
export type GreaterThanOrEqual<T extends number | bigint, U extends number | bigint> = Compare<T, U> extends 1 | 0 ? true : false; | ||
export type Max<T extends number | bigint, U extends number | bigint> = Compare<T, U> extends 1 | 0 ? T : U; | ||
export type Min<T extends number | bigint, U extends number | bigint> = Compare<T, U> extends 1 | 0 ? U : T; |
@@ -8,2 +8,2 @@ export type { Abs } from "./absolute"; | ||
export type { Power } from "./power"; | ||
export type { Compare, Equal, NotEqual, LessThan, LessThanOrEqual, GreaterThan, GreaterThanOrEqual, } from "./compare"; | ||
export type { Compare, Equal, NotEqual, LessThan, LessThanOrEqual, GreaterThan, GreaterThanOrEqual, Max, Min, } from "./compare"; |
@@ -136,2 +136,30 @@ import { Fn, unset, _ } from "../core/Core"; | ||
/** | ||
* Returns the max between 2 numbers. | ||
* @param n1 - first number or bigint | ||
* @param n2 - second number or bigint | ||
* @returns the maximum values between the two | ||
* @example | ||
* ```ts | ||
* type T0 = Eval<Numbers.Max<1, 2>>; // 2 | ||
* ``` | ||
*/ | ||
export type Max<n1 extends number | bigint | _ | unset = unset, n2 extends number | bigint | _ | unset = unset> = Functions.PartialApply<MaxFn, [n1, n2]>; | ||
export interface MaxFn extends Fn { | ||
return: Impl.Max<Extract<this["arg0"], number | bigint>, Extract<this["arg1"], number | bigint>>; | ||
} | ||
/** | ||
* Returns the min between 2 numbers. | ||
* @param n1 - first number or bigint | ||
* @param n2 - second number or bigint | ||
* @returns the minimum values between the two | ||
* @example | ||
* ```ts | ||
* type T0 = Eval<Numbers.Min<1, 2>>; // 1 | ||
* ``` | ||
*/ | ||
export type Min<n1 extends number | bigint | _ | unset = unset, n2 extends number | bigint | _ | unset = unset> = Functions.PartialApply<MinFn, [n1, n2]>; | ||
export interface MinFn extends Fn { | ||
return: Impl.Min<Extract<this["arg0"], number | bigint>, Extract<this["arg1"], number | bigint>>; | ||
} | ||
/** | ||
* Power of a number | ||
@@ -138,0 +166,0 @@ * @description the number can be of different types (bigint or number) and handle really large numbers |
import { GetFromPath, IsArrayStrict, Prettify, Primitive, UnionToIntersection } from "../helpers"; | ||
import { arg, Call, Call2, Fn, unset, _ } from "../core/Core"; | ||
import { Apply, Call, Call2, Fn, unset, _ } from "../core/Core"; | ||
import { Std } from "../std/Std"; | ||
@@ -126,3 +126,3 @@ import { Strings } from "../strings/Strings"; | ||
} | ||
type CreateImpl<pattern, args extends unknown[]> = pattern extends arg<infer N extends number> ? args[N] : pattern extends Primitive ? pattern : pattern extends [any, ...any] ? { | ||
type CreateImpl<pattern, args extends unknown[]> = pattern extends infer p extends Fn ? Apply<p, args> : pattern extends Primitive ? pattern : pattern extends [any, ...any] ? { | ||
[key in keyof pattern]: CreateImpl<pattern[key], args>; | ||
@@ -129,0 +129,0 @@ } : pattern extends (infer V)[] ? CreateImpl<V, args>[] : pattern extends object ? { |
@@ -102,3 +102,4 @@ import { Fn, unset, _ } from "../core/Core"; | ||
infer To extends string, | ||
infer Str | ||
infer Str, | ||
...any | ||
] ? Impl.Replace<Str, From, To> : never; | ||
@@ -136,3 +137,3 @@ } | ||
export interface SplitFn extends Fn { | ||
return: this["args"] extends [infer Sep extends string, infer Str] ? Impl.Split<Str, Sep> : never; | ||
return: this["args"] extends [infer Sep extends string, infer Str, ...any] ? Impl.Split<Str, Sep> : never; | ||
} | ||
@@ -139,0 +140,0 @@ /** |
import { Functions as F, Functions } from "../functions/Functions"; | ||
import { Numbers as N, Numbers } from "../numbers/Numbers"; | ||
import { Call, Call2, Eval, Fn, Pipe, unset, _ } from "../core/Core"; | ||
import { Apply, args, Call, Call2, Eval, Fn, Pipe, unset, _ } from "../core/Core"; | ||
import { Iterator, Stringifiable } from "../helpers"; | ||
import { Objects } from "../objects/Objects"; | ||
export declare namespace Tuples { | ||
@@ -26,16 +27,2 @@ type HeadImpl<xs> = xs extends readonly [infer head, ...any] ? head : never; | ||
type IsEmptyImpl<tuple extends unknown[]> = [] extends tuple ? true : false; | ||
interface CreateFn extends Fn { | ||
return: this["args"]; | ||
} | ||
/** | ||
* Create a tuple from a list of arguments. | ||
* @param args - The arguments to create a tuple from. | ||
* @returns A tuple containing the arguments. | ||
* @example | ||
* ```ts | ||
* type T0 = Call3<Tuples.Create, 1, 2, 3>; // [1, 2, 3] | ||
* type T1 = Eval<Tuples.Create<1, 2, 3>>; // [1, 2, 3] | ||
* ``` | ||
*/ | ||
export type Create<arg1 = unset, arg2 = unset, arg3 = unset, arg4 = unset, arg5 = unset> = Functions.PartialApply<CreateFn, [arg1, arg2, arg3, arg4, arg5]>; | ||
interface IsEmptyFn extends Fn { | ||
@@ -131,3 +118,3 @@ return: IsEmptyImpl<Extract<this["arg0"], unknown[]>>; | ||
*/ | ||
export type Map<fn extends Fn, tuple extends readonly any[] | unset = unset> = Functions.PartialApply<MapFn, [fn, tuple]>; | ||
export type Map<fn extends Fn | unset | _ = unset, tuple extends readonly any[] | unset = unset> = Functions.PartialApply<MapFn, [fn, tuple]>; | ||
interface MapFn extends Fn { | ||
@@ -444,14 +431,13 @@ return: this["args"] extends [ | ||
} | ||
type ZipWithImpl<arr1 extends unknown[], arr2 extends unknown[], fn extends Fn, acc extends unknown[] = []> = [arr1, arr2] extends [ | ||
[ | ||
infer item1, | ||
...infer rest1 | ||
], | ||
[ | ||
infer item2, | ||
...infer rest2 | ||
] | ||
] ? ZipWithImpl<rest1, rest2, fn, [...acc, Call2<fn, item1, item2>]> : acc; | ||
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>>> : never; | ||
} | ||
interface ZipWithFn<fn extends Fn> extends Fn { | ||
return: ZipWithImpl<Extract<this["arg0"], unknown[]>, Extract<this["arg1"], unknown[]>, fn>; | ||
return: this["args"] extends infer arrays extends unknown[][] ? Pipe<arrays, [ | ||
Tuples.Map<Objects.Get<"length">>, | ||
Tuples.Reduce<Numbers.Min, 9999>, | ||
Numbers.Sub<_, 1>, | ||
Tuples.Range<0, _>, | ||
Tuples.Map<ZipWithMapper<fn, arrays>> | ||
]> : never; | ||
} | ||
@@ -471,3 +457,14 @@ /** | ||
*/ | ||
export type Zip<arr1 extends unknown[] | _ | unset = unset, arr2 extends unknown[] | _ | unset = unset> = Functions.PartialApply<ZipWithFn<CreateFn>, [arr1, arr2]>; | ||
export type Zip<arr0 extends unknown[] | _ | unset = unset, arr1 extends unknown[] | _ | unset = unset, arr2 extends unknown[] | _ | unset = unset, arr3 extends unknown[] | _ | unset = unset, arr4 extends unknown[] | _ | unset = unset, arr5 extends unknown[] | _ | unset = unset, arr6 extends unknown[] | _ | unset = unset, arr7 extends unknown[] | _ | unset = unset, arr8 extends unknown[] | _ | unset = unset, arr9 extends unknown[] | _ | unset = unset> = Functions.PartialApply<ZipWith<args>, [ | ||
arr0, | ||
arr1, | ||
arr2, | ||
arr3, | ||
arr4, | ||
arr5, | ||
arr6, | ||
arr7, | ||
arr8, | ||
arr9 | ||
]>; | ||
/** | ||
@@ -485,8 +482,19 @@ * Zip two tuples together using a function. | ||
* ```ts | ||
* type T0 = Call2<Tuples.ZipWith<Tuples.Create>, [1, 2, 3], [10, 2, 5]>; // [[1, 10], [2, 2], [3, 5]] | ||
* type T1 = Eval<Tuples.ZipWith<Tuples.Create, [1, 2, 3], [10, 2, 5]>>; // [[1, 10], [2, 2], [3, 5]] | ||
* 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] | ||
* ``` | ||
*/ | ||
export type ZipWith<fn extends Fn, arr1 extends unknown[] | _ | unset = unset, arr2 extends unknown[] | _ | unset = unset> = Functions.PartialApply<ZipWithFn<fn>, [arr1, arr2]>; | ||
export type ZipWith<fn extends Fn, arr0 extends unknown[] | _ | unset = unset, arr1 extends unknown[] | _ | unset = unset, arr2 extends unknown[] | _ | unset = unset, arr3 extends unknown[] | _ | unset = unset, arr4 extends unknown[] | _ | unset = unset, arr5 extends unknown[] | _ | unset = unset, arr6 extends unknown[] | _ | unset = unset, arr7 extends unknown[] | _ | unset = unset, arr8 extends unknown[] | _ | unset = unset, arr9 extends unknown[] | _ | unset = unset> = Functions.PartialApply<ZipWithFn<fn>, [ | ||
arr0, | ||
arr1, | ||
arr2, | ||
arr3, | ||
arr4, | ||
arr5, | ||
arr6, | ||
arr7, | ||
arr8, | ||
arr9 | ||
]>; | ||
/** | ||
@@ -493,0 +501,0 @@ * Range takes a `start` and an `end` integer and produces |
{ | ||
"name": "hotscript", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Type-level madness", | ||
@@ -15,3 +15,3 @@ "type": "module", | ||
"perf": "tsc --project test/tsconfig.json --noEmit --extendedDiagnostics", | ||
"fmt": "prettier ./src/** ./tests/** -w", | ||
"fmt": "prettier ./src/** ./test/** -w", | ||
"check": "tsc --strict --noEmit --extendedDiagnostics" | ||
@@ -18,0 +18,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155545
4170