pragmatic-fp-ts
Version:
Opinionated functional programming library with easy use in mind
22 lines (18 loc) • 560 B
text/typescript
import { getValueOr } from "./main.ts";
export function pick<V extends {}, K extends keyof V>(
props: K[],
dict: V
): Pick<V, K>;
export function pick<V extends {}, K extends keyof V>(
props: K[]
): (dict: V) => Pick<V, K>;
export function pick<V extends {}, K extends keyof V>(props: K[], dict?: V) {
if (arguments.length === 1) {
return (_dict: V) => pick(props, _dict) as any;
}
const dd = getValueOr({} as any, dict);
return getValueOr([], props).reduce((accum, key) => {
accum[key] = dd[key];
return accum;
}, {} as any);
}