rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
41 lines (37 loc) • 1.05 kB
TypeScript
import type {
Args,
Call1W,
Fn1,
GenericFn,
GenericResolver,
GenericReturn1W,
Param0,
Return,
} from "../HKT";
/**
* Apply a function to each value in an object.
*
* Sig: `<T, U>(f: (x: T => U), o: Record<PropertyKey, T>) => Record<PropertyKey, U>`
*/
export type MapValues<F extends Fn1, O extends object> = {
[K in keyof O]: Call1W<F, O[K]>;
};
interface Resolver extends GenericResolver<[Fn1, object], object> {
on1_: ([f]: Args<this>) => [
[Record<PropertyKey, Param0<typeof f>>],
Record<PropertyKey, Return<typeof f>>,
];
on_1: ([, o]: Args<this>) => [[Fn1<(typeof o)[keyof typeof o]>], object];
on11: ([f, o]: Args<this>) => [
[],
Record<keyof typeof o, GenericReturn1W<typeof f, (typeof o)[keyof typeof o]>>,
];
}
/**
* [Fn] Apply a function to each value in an object.
*
* Sig: `<T, U>(f: (x: T => U), o: Record<PropertyKey, T>) => Record<PropertyKey, U>`
*/
export default interface MapValuesFn extends GenericFn<Resolver> {
def: ([f, o]: Args<this>) => MapValues<typeof f, typeof o>;
}