I have a finite set of function factories with similar return types, each of which returns a crud operation (but could be any operation, for the sake of this question). The return type of operation is Promise, for simplicity.
I want to convert a statically typed object of function constructors into a statically typed object of returned from these constructors functions, namely:
{f1: (k: K) => (...) => Promise<...>, f2: (k: K) => (...) => Promise<...>}
should become
{f1: (...) => Promise<...>, f2: (...) => Promise<...>}
when a key K is applied.
As a more concrete example:
type K = 'a' | 'b';
const makeGet = (k: K): (id: string): Promise<DbRecord<K>> => {...}
const makeSet = (k: K): (id: string, Partial<DbRecord<K>>): Promise<void> => {...}
const fs = {get: makeGet, set: makeSet} as const;
export const makeCrud = (k: K) => mapValues(fs, (f) => f(k)); // mapValues is a function I'm looking for
So far I manage to get only a record-like return (i.e. trying lodash mapValues or fp-ts Record.map): (pseudocode) {f1: typeof f1(k) | typeof f2(k), f2: typeof f1(k) | typeof f2(k)}, and my goal is to get a more precise mapping (pseudocode) {f1: typeof f1(k), f2: typeof f2(k)}
I have a hunch fp-ts has something for this, but I can't seem to find a right tool.
Is there such, or maybe a similar mapValues that respects k=>v static relation can be written manually?