uinix-fp-map-entries
v1.0.0
Published
uinix fp object map entries utility
Downloads
4
Maintainers
Readme
uinix-fp-map-entries
uinix-fp
object map entries utility.
Install
This package is ESM-only and requires Node 12+.
npm install uinix-fp-map-entries
Use
mapEntries
applies the provided mapper over an object's entries. It is recommended that the provided objects follow a single value interface when used with mapEntries
.
import {mapEntries} from 'uinix-fp-map-entries';
const squareEntries = ([_k, v]) => v ** 2;
mapEntries(squareEntries)({a: 1, b: 2, c: 3}); // {a: 1, b: 4, c: 9}
const mapSquareEntries = mapEntries(squareEntries); // curried
mapSquareEntries({a: 1, b: 2, c: 3}); // {a: 1, b: 4, c: 9}
const keyedSquareEntries = ([k, v]) => k.startsWith('a') ? v ** 2 : v;
mapEntries(keyedSquareEntries)({a1: 2, b1: 3, a2: 4, b2: 5}); // {a1: 4, b1: 3, a2: 16, b2: 5}
API
This package exports the following identifiers: mapEntries
. There is no default export.
mapEntries(f)(object)
Parameters (Curried)
f
((x: X) => Y
): The mapping functionobject
(Record<string, X>
): An object with values of a single type.
Returns
Record<string, Y>
— An object with mapped values of a single type.