UNPKG

rivo

Version:

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

51 lines (47 loc) • 1.5 kB
import type { Applicative, Applicative$GetTypeClassW } from "."; import type { Args, Call2W, Fn1, GenericFn, GenericResolver, GenericReturn1W, Param0W, ReturnW, } from "../../HKT"; import type { HKT$Extract, HKT$GetConstruct, HKT$Mutate } from "../HKT"; /** * Apply an {@link Applicative} of a function to an {@link Applicative} of a value. * * Sig: `<F<~>, T, U>(fab: F<(x: T) => U>, f: F<T>) => F<U>` */ export type Ap< FAB extends HKT$Mutate<F, Fn1<HKT$Extract<F>, unknown>>, F extends Applicative, > = Call2W<Applicative$GetTypeClassW<F>["Ap"], FAB, F>; interface Resolver extends GenericResolver<[Applicative<Fn1>, Applicative], Applicative> { on1_: ([fab]: Args<this>) => [ [HKT$Mutate<typeof fab, Param0W<HKT$Extract<typeof fab>>>], HKT$Mutate<typeof fab, ReturnW<HKT$Extract<typeof fab>>>, ]; on_1: ([, f]: Args<this>) => [ [HKT$Mutate<typeof f, Fn1<HKT$Extract<typeof f>, unknown>>], HKT$GetConstruct<typeof f>, ]; on11: ([fab, f]: Args<this>) => [ [], HKT$Mutate<typeof fab, GenericReturn1W<HKT$Extract<typeof fab>, HKT$Extract<typeof f>>>, ]; } /** * [Fn] Apply an {@link Applicative} of a function to an {@link Applicative} of a value. * * Sig: `<F<~>, T, U>(fab: F<(x: T) => U>, f: F<T>) => F<U>` */ export default interface ApFn extends GenericFn<Resolver> { def: ([fab, f]: Args<this>) => typeof fab extends ( HKT$Mutate<typeof f, Fn1<HKT$Extract<typeof f>, unknown>> ) ? Ap<typeof fab, typeof f> : never; }