source: node_modules/ramda/src/pluck.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d24f17c]1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4
5var map =
6/*#__PURE__*/
7require("./map.js");
8
9var prop =
10/*#__PURE__*/
11require("./prop.js");
12/**
13 * Returns a new list by plucking the same named property off all objects in
14 * the list supplied.
15 *
16 * `pluck` will work on
17 * any [functor](https://github.com/fantasyland/fantasy-land#functor) in
18 * addition to arrays, as it is equivalent to `R.map(R.prop(k), f)`.
19 *
20 * @func
21 * @memberOf R
22 * @since v0.1.0
23 * @category List
24 * @sig Functor f => k -> f {k: v} -> f v
25 * @param {Number|String} key The key name to pluck off of each object.
26 * @param {Array} f The array or functor to consider.
27 * @return {Array} The list of values for the given key.
28 * @see R.project, R.prop, R.props
29 * @example
30 *
31 * var getAges = R.pluck('age');
32 * getAges([{name: 'fred', age: 29}, {name: 'wilma', age: 27}]); //=> [29, 27]
33 *
34 * R.pluck(0, [[1, 2], [3, 4]]); //=> [1, 3]
35 * R.pluck('val', {a: {val: 3}, b: {val: 5}}); //=> {a: 3, b: 5}
36 * @symb R.pluck('x', [{x: 1, y: 2}, {x: 3, y: 4}, {x: 5, y: 6}]) = [1, 3, 5]
37 * @symb R.pluck(0, [[1, 2], [3, 4], [5, 6]]) = [1, 3, 5]
38 */
39
40
41var pluck =
42/*#__PURE__*/
43_curry2(function pluck(p, list) {
44 return map(prop(p), list);
45});
46
47module.exports = pluck;
Note: See TracBrowser for help on using the repository browser.