hkt-toolbelt
Version:
Functional and composable type utilities
20 lines (19 loc) • 556 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.atKey = void 0;
const __1 = require("..");
/**
* Given an object and a key, return the value at the specified key.
*
* @param {Record<PropertyKey, unknown>} x - The object to get the value from.
* @param {PropertyKey} k - The key to get the value of.
*
* @example
* ```ts
* import { Object } from "hkt-toolbelt";
*
* const result = Object.atKey({ a: 1, b: 2, c: 3 })('a')
* // ^? 1
* ```
*/
exports.atKey = ((x) => (k) => k in x ? x[k] : __1.Type.never);