rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
39 lines (35 loc) • 1.21 kB
TypeScript
import type { List } from ".";
import type {
Args,
Call1W,
Fn1,
GenericFn,
GenericResolver,
GenericReturn1W,
Param0,
Return,
} from "../HKT";
/**
* Apply a function to each element of a {@link List} (i.e., fixed-length tuple).
*
* Sig: `<T, U>(f: (x: T) => U, xs: List<T>) => List<U>`
*/
export type Map<F extends Fn1, TS extends List> = {
[K in keyof TS]: Call1W<F, TS[K]>;
};
interface Resolver extends GenericResolver<[Fn1, List], List> {
on1_: ([f]: Args<this>) => [[List<Param0<typeof f>>], List<Return<typeof f>>];
on_1: ([, xs]: Args<this>) => [[Fn1<(typeof xs)[number]>], List];
on11: ([f, xs]: Args<this>) => [[], List<GenericReturn1W<typeof f, (typeof xs)[number]>>];
on__r: ([, , r]: Args<this>) => [Fn1<never, (typeof r)[number]>, List];
on1_r: ([f, , r]: Args<this>) => [List<Param0<typeof f>>];
on_1r: ([, xs, r]: Args<this>) => [Fn1<(typeof xs)[number], (typeof r)[number]>];
}
/**
* [Fn] Apply a function to each element of a {@link List} (i.e., fixed-length tuple).
*
* Sig: `<T, U>(f: (x: T) => U, xs: List<T>) => List<U>`
*/
export default interface MapFn extends GenericFn<Resolver> {
def: ([f, xs]: Args<this>) => Map<typeof f, typeof xs>;
}