UNPKG

fp-ts-std

Version:

The missing pseudo-standard library for fp-ts.

22 lines (21 loc) 788 B
import * as RA from "fp-ts/ReadonlyArray"; import { pipe } from "fp-ts/function"; import { uncurry2 } from "./Function"; import { fanout } from "./Tuple"; export const merge = (x) => (y) => ({ ...x, ...y }); export const pick = (ks) => (x) => pipe(ks, RA.reduce({}, (ys, k) => merge(ys)(k in x ? { [k]: x[k] } : {}))); export const pickFrom = () => pick; export const get = (k) => (x) => x[k]; export const omit = (ks) => (x) => { const y = { ...x }; for (const k of ks) { delete y[k]; } return y; }; export const omitFrom = () => omit; export const withDefaults = merge; export const renameKey = (oldK) => (newK) => (x) => { const newO = (x) => (oldK in x ? { [newK]: x[oldK] } : {}); return pipe(x, fanout(omitFrom()([oldK]))(newO), uncurry2(merge)); };