{"version":3,"file":"hkt.mjs","names":[],"sources":["../src/hkt.ts"],"sourcesContent":["/** Symbol key for the argument tuple applied to an HKT instance. */\nconst PARAMS = Symbol(\"prodkit.hkt.params\");\n\n/** Symbol key for the applied type produced by an HKT instance. */\nconst TYPE = Symbol(\"prodkit.hkt.type\");\n\n/**\n * Encoding for a higher-kinded type\n *\n * @example\n * type Maybe<A> =\n *   | { readonly _tag: \"Some\"; readonly value: A }\n *   | { readonly _tag: \"None\" };\n *\n * interface MaybeF extends HKT {\n *   readonly [HKT.TYPE]: Maybe<HKT.Param<this, 0>>;\n * }\n *\n * type Name = HKT.Apply<MaybeF, readonly [string]>;\n * //   ^? Maybe<string>\n */\nexport interface HKT extends HKT.Parameterized<readonly unknown[]> {\n  readonly [TYPE]: unknown;\n}\n\nexport const HKT = Object.freeze({ PARAMS, TYPE });\n\nexport namespace HKT {\n  export type PARAMS = typeof PARAMS;\n  export type TYPE = typeof TYPE;\n\n  /** Phantom slot carrying the argument tuple for an {@link Apply} instantiation. */\n  export interface Parameterized<Args extends readonly unknown[]> {\n    readonly [PARAMS]: Args;\n  }\n\n  /** Gets the `N`th argument from an HKT instance */\n  export type Param<Self extends HKT, N extends keyof Self[PARAMS]> = Self[PARAMS][N];\n\n  /**\n   * Value-level witness that constructor `F` is already applied to `Args`.\n   *\n   * Compositional helpers such as {@link Fix12} should target the bare constructor\n   * (`Fix12<F, ...>`), not `Fix12<Applied<F, Args>, ...>`: {@link Apply} intersects a new\n   * arg tuple onto `[PARAMS]`, so rebinding an {@link Applied} instance collides with the\n   * stored tuple and collapses slots to `never`.\n   */\n  export type Applied<F extends HKT, Args extends readonly unknown[]> = F & Parameterized<Args>;\n\n  /** Applies HKT `F` to argument tuple `Args` and returns the `[TYPE]` type. */\n  export type Apply<F extends HKT, Args extends readonly unknown[]> = (F &\n    Parameterized<Args>)[typeof TYPE];\n\n  /** Composes two HKTs: the applied type of `G` on the first argument flows into `F`. */\n  export interface Compose<F extends HKT, G extends HKT> extends HKT {\n    readonly [TYPE]: Apply<F, [Apply<G, [Param<this, 0>]>]>;\n  }\n\n  /** Swaps the first two arguments before applying `F`. */\n  export interface Flip<F extends HKT> extends HKT {\n    readonly [TYPE]: Apply<F, [Param<this, 1>, Param<this, 0>]>;\n  }\n\n  /** Fixes the first argument to `A` before applying `F`. */\n  export interface Fix1<F extends HKT, A> extends HKT {\n    readonly [TYPE]: Apply<F, [A, Param<this, 0>]>;\n  }\n\n  /** Fixes the second argument to `B` before applying `F`. */\n  export interface Fix2<F extends HKT, B> extends HKT {\n    readonly [TYPE]: Apply<F, [Param<this, 0>, B]>;\n  }\n\n  /** Fixes the first two arguments to `A` and `B` before applying `F`. */\n  export interface Fix12<F extends HKT, A, B> extends HKT {\n    readonly [TYPE]: Apply<F, [A, B, Param<this, 0>]>;\n  }\n}\n"],"mappings":"AAyBA,MAAa,MAAM,OAAO,OAAO;CAAE,QAxBpB,OAAO,oBAwBa;CAAQ,MArB9B,OAAO,kBAqBuB;AAAK,CAAC"}