about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/mapObjIndexedReturnArray.js
blob: 83c6634f7c84e2d7557a1474d42e6ebbd9ef9a44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const _curry2 = require('ramda/src/internal/_curry2')
const _map = require('ramda/src/internal/_map')
const keys = require('ramda/src/keys')

// mapObjIndexed: ((v, k, {k: v}) → v') → {k: v} → {k: v'}
// mapObjIndexedReturnArray: ((v, k, {k: v}) → v') → {k: v} → [v']

/*
 * @example
 *
 *      const xyz = { x: 1, y: 2, z: 3 };
 *      const prependKeyAndDouble = (num, key, obj) => key + (num * 2);
 *
 *      mapObjIndexedReturnArray(prependKeyAndDouble, xyz); //=> ['x2', 'y4', 'z6']
 */

const mapObjIndexedReturnArray = _curry2((fn, obj) =>
  _map(key => fn(obj[key], key, obj), keys(obj)),
)

module.exports = mapObjIndexedReturnArray