import { Call, Fn, PartialApply, unset, _ } from "../core/Core"; import { UnionToIntersection, UnionToTuple } from "../helpers"; import { Std } from "../std/Std"; import { Tuples } from "../tuples/Tuples"; export declare namespace Unions { export type Extract = PartialApply; interface ExtractFn extends Fn { return: Std._Extract; } type ExtractByImpl = union extends any ? Call extends true ? union : never : never; export interface ExtractBy extends Fn { return: ExtractByImpl; } export type Exclude = PartialApply; interface ExcludeFn extends Fn { return: Std._Exclude; } type ExcludeByImpl = union extends any ? Call extends true ? never : union : never; export interface ExcludeBy extends Fn { return: ExcludeByImpl; } type MapImpl = union extends any ? Call : never; export type Map = PartialApply; interface MapFn extends Fn { return: this["args"] extends [infer fn extends Fn, infer u] ? MapImpl : never; } /** * `Unions.Range` takes a `start` and an `end` integer and produces * a union containing integer ranging from `start` to `end` * @param start - the start of the range (included) * @param end - the end of the range (included) * @returns a union of integers * @example * ```ts * type T0 = Call, 7>; // 3 | 4 | 5 | 6 | 7 * type T1 = Call, 5>; // 5 | 6 | 7 | 8 | 9 | 10 * type T3 = Call, 5>; // -2 | 1 | 0 | 1 | 2 * type T4 = Call, 5>; // -5 | -4 | -3 | -2 * ``` */ export type Range = PartialApply; interface RangeFn extends Fn { return: this["args"] extends [ infer start extends number, infer end extends number ] ? Call>[number] : never; } /** * `Unions.ToTuple` turns a union type into a tuple. * Warning: the ordering of the output tuple is not stable. * @param union - any union type. * @returns a tuple containing each member of this union type. * @example * ```ts * type T0 = Call; // [1, 2, 3] * ``` */ export type ToTuple = PartialApply; interface ToTupleFn extends Fn { return: this["args"] extends [infer union, ...any] ? UnionToTuple : never; } /** * `Unions.NonNullable` excludes null and undefined from the union type. * @param union - any union type. * @returns a union which is excluded by null and undefined. * @example * ```ts * type T0 = Call; // 1 | "a" * type T1 = Pipe<"a" | 1 | null | undefined, [U.NonNullable]>; // 1 | "a" * type T2 = Call>; // 1 | "a" * ``` */ export type NonNullable = PartialApply; interface NonNullableFn extends Fn { return: this["arg0"] extends infer union ? Std._NonNullable : never; } /** * `Unions.ToIntersection` turns a union type into an intersection type. * @param union - any union type. * @returns an intersection of all member of the union * @example * ```ts * type T0 = Call; // {a: string} & {b: number} * ``` */ export type ToIntersection = PartialApply; interface ToIntersectionFn extends Fn { return: this["args"] extends [infer union, ...any] ? UnionToIntersection : never; } export {}; }