UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

33 lines (29 loc) • 1.03 kB
import type { Ary } from "."; import type { Args, GenericFn, GenericResolver } from "../HKT"; /** * Mutate the element type of an {@link Ary} (i.e., `Array` or `ReadonlyArray`). * * Sig: `<T, U>(y: U, a: Ary<T>) => Ary<U>` * * @example * ```typescript * type R1 = Mutate<number, string[]>; * // ^?: number[] * type R2 = Mutate<"foo", readonly number[]>; * // ^?: readonly "foo"[] * ``` */ export type Mutate<U, A extends Ary> = A extends unknown[] ? U[] : readonly U[]; interface Resolver extends GenericResolver<[unknown, Ary<unknown>], Ary<unknown>> { on1_: ([y]: Args<this>) => [[Ary<unknown>], Ary<unknown>]; on_1: ([, a]: Args<this>) => [[unknown], Ary<unknown>]; on11: ([y, a]: Args<this>) => [[], Mutate<typeof y, typeof a>]; } /** * [Fn] Mutate the element type of an {@link Ary} (i.e., `Array` or `ReadonlyArray`). * * Sig: `<T, U>(y: U, a: Ary<T>) => Ary<U>` */ export default interface MutateFn extends GenericFn<Resolver> { def: ([y, a]: Args<this>) => Mutate<typeof y, typeof a>; }