import { If } from "../boolean"; import { ElementOf, IsEmpty, List, Pairs, Reverse } from "../list"; import { Extends, MutuallyAssignable, Satisfies } from "../type"; import { $, HKT, _, I, O } from "."; import { $All } from "./list"; /** * checks whether the first element in a pair of hkts can be piped into the second */ interface IsPairPipeable extends HKT { [HKT.i]: Satisfies<_, [HKT, HKT]>; [HKT.o]: Extends[0]>, I[1]>>; } /** * checks if a list of hkts is composable * * @since 0.0.2 */ export type $IsPipeable> = MutuallyAssignable>>; /** * checks if a list of hkts is composable * * @since 0.0.2 */ export type $IsComposable> = MutuallyAssignable>>>; /** * pipes input `X` through list of hkts `Kinds` * * Assumes `Kinds` contains no optional elements, as as of the time of this being written (0.1.0), * this type is only used by `$Compose` and `$Pipe`, * both of which ensure that the type passed in is composable and don't allow for optional elements */ type __$Pipe, X> = IsEmpty extends true ? X : Kinds extends readonly [infer H, ...infer T] ? __$Pipe>, $, Satisfies>>>> : Kinds extends readonly [...infer Init, infer L] ? __$Pipe>, $, HKT>, Satisfies>>, HKT>>>>> : X; /** * loosely typed `Pipe` that doesn't validate that the input type is pipeable. * * exists mostly because `Compose` uses `Pipe` logic but TS can't properly detect that if `L` is composable then `Rev` is pipeable */ type _$Pipe, X> = __$Pipe; /** * pipes `X` through HKTs `Kinds` and returns the resultant type * * @since 0.0.2 * * @example * ```ts * // some sample kinds for transforming an input * type sb = HKT * type sn = HKT * type ss = HKT * type nb = HKT * type nn = HKT * type ns = HKT * * type e0 = $Pipe<[], never> // never * type e1 = $Pipe<[], string> // string * type e2 = $Pipe // string * type e3 = $Pipe<[sn], string> // number * type e4 = $Pipe<[sn, nb], string> // boolean * type e5 = $Pipe<[...ss[], sn], string> // number * type e6 = $Pipe<[sn, ...nn[]], string> // number * type e7 = $Pipe<[sn, ...nn[], nb], string> // boolean * type e8 = $Pipe // Type 'sn[]' does not satisfy the constraint 'never'.ts(2344) * type e9 = $Pipe<[sn, ...nn[], (ns | sn), sb], string> // Type '[sn, ...nn[], sn | ns, sb]' does not satisfy the constraint 'never'.ts(2344) * type e10 = $Pipe<[sn, ...nn[], (ns | sn), nb], string> // Type '[sn, ...nn[], sn | ns, nb]' does not satisfy the constraint 'never'.ts(2344 * type e11 = $Pipe<[sn, ...(ns | sn)[]], string> // Type '[sn, ...(sn | ns)[]]' does not satisfy the constraint 'never'.ts(2344) * ``` */ export type $Pipe, List>, X> = _$Pipe; /** * @since 0.0.2 */ export interface Pipe, List>> extends HKT { [HKT.i]: _; [HKT.o]: $Pipe>; } /** * @since 0.0.2 */ export type $Compose, List>, X> = _$Pipe, X>; /** * @since 0.0.2 */ export interface Compose, List>> extends HKT { [HKT.i]: _; [HKT.o]: $Compose>; } export {}; //# sourceMappingURL=composition.d.ts.map