UNPKG

hkt-toolbelt

Version:

Functional and composable type utilities

26 lines (25 loc) 640 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pick = void 0; /** * Given a list of keys and an object, return a new object with only the * specified keys. * * @param {PropertyKey[]} k - The list of keys to pick. * @param {Record<PropertyKey, unknown>} o - The object to pick from. * * @example * ```ts * import { Object } from "hkt-toolbelt"; * * const result = Object.pick(['foo'])({ foo: 'bar', baz: 'qux' }) * // ^? { foo: 'bar' } * ``` */ exports.pick = ((k) => (o) => { const result = {}; for (const key of k) { result[key] = o[key]; } return result; });