props.js 928 B

123456789101112131415161718192021222324252627282930313233
  1. import _curry2 from "./internal/_curry2.js";
  2. import path from "./path.js";
  3. /**
  4. * Acts as multiple `prop`: array of keys in, array of values out. Preserves
  5. * order.
  6. *
  7. * @func
  8. * @memberOf R
  9. * @since v0.1.0
  10. * @category Object
  11. * @sig [k] -> {k: v} -> [v]
  12. * @param {Array} ps The property names to fetch
  13. * @param {Object} obj The object to query
  14. * @return {Array} The corresponding values or partially applied function.
  15. * @see R.prop, R.pluck, R.project
  16. * @example
  17. *
  18. * R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2]
  19. * R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2]
  20. *
  21. * const fullName = R.compose(R.join(' '), R.props(['first', 'last']));
  22. * fullName({last: 'Bullet-Tooth', age: 33, first: 'Tony'}); //=> 'Tony Bullet-Tooth'
  23. */
  24. var props =
  25. /*#__PURE__*/
  26. _curry2(function props(ps, obj) {
  27. return ps.map(function (p) {
  28. return path([p], obj);
  29. });
  30. });
  31. export default props;