UNPKG

rivo

Version:

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

47 lines (43 loc) • 1.2 kB
import type { Functor, Functor$GetTypeClassW } from "."; import type { Args, Call2W, Fn1, GenericFn, GenericResolver, GenericReturn1W, Param0, Return, } from "../../HKT"; import type { HKT$Extract, HKT$GetConstruct, HKT$Mutate } from "../HKT"; /** * Map a {@link Functor} through a function. * * Sig: `<F<~>, T, U>(f: (x: T) => U, fa: F<T>) => F<U>` */ export type Map<F extends Fn1, FA extends Functor<Param0<F>>> = Call2W< Functor$GetTypeClassW<FA>["Map"], F, FA >; interface Resolver extends GenericResolver<[Fn1, Functor], Functor> { on1_: ([f]: Args<this>) => [[Functor<Param0<typeof f>>], Functor<Return<typeof f>>]; on_1: ([, fa]: Args<this>) => [ [Fn1<HKT$Extract<typeof fa>, unknown>], HKT$GetConstruct<typeof fa>, ]; on11: ([f, fa]: Args<this>) => [ [], HKT$Mutate<typeof fa, GenericReturn1W<typeof f, HKT$Extract<typeof fa>>>, ]; } /** * [Fn] Map a {@link Functor} through a function. * * Sig: `<F<~>, T, U>(fa: F<T>, f: (x: T) => U) => F<U>` */ export default interface MapFn extends GenericFn<Resolver> { def: ([f, fa]: Args<this>) => typeof fa extends Functor<Param0<typeof f>> ? Map<typeof f, typeof fa> : never; }