You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
820 B

4 years ago
  1. import _curry1 from "./internal/_curry1.js";
  2. /**
  3. * Creates a new object from a list key-value pairs. If a key appears in
  4. * multiple pairs, the rightmost pair is included in the object.
  5. *
  6. * @func
  7. * @memberOf R
  8. * @since v0.3.0
  9. * @category List
  10. * @sig [[k,v]] -> {k: v}
  11. * @param {Array} pairs An array of two-element arrays that will be the keys and values of the output object.
  12. * @return {Object} The object made by pairing up `keys` and `values`.
  13. * @see R.toPairs, R.pair
  14. * @example
  15. *
  16. * R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3}
  17. */
  18. var fromPairs =
  19. /*#__PURE__*/
  20. _curry1(function fromPairs(pairs) {
  21. var result = {};
  22. var idx = 0;
  23. while (idx < pairs.length) {
  24. result[pairs[idx][0]] = pairs[idx][1];
  25. idx += 1;
  26. }
  27. return result;
  28. });
  29. export default fromPairs;