unionWith.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import _concat from "./internal/_concat.js";
  2. import _curry3 from "./internal/_curry3.js";
  3. import uniqWith from "./uniqWith.js";
  4. /**
  5. * Combines two lists into a set (i.e. no duplicates) composed of the elements
  6. * of each list. Duplication is determined according to the value returned by
  7. * applying the supplied predicate to two list elements. If an element exists
  8. * in both lists, the first element from the first list will be used.
  9. *
  10. * @func
  11. * @memberOf R
  12. * @since v0.1.0
  13. * @category Relation
  14. * @sig ((a, a) -> Boolean) -> [*] -> [*] -> [*]
  15. * @param {Function} pred A predicate used to test whether two items are equal.
  16. * @param {Array} list1 The first list.
  17. * @param {Array} list2 The second list.
  18. * @return {Array} The first and second lists concatenated, with
  19. * duplicates removed.
  20. * @see R.union
  21. * @example
  22. *
  23. * const l1 = [{a: 1}, {a: 2}];
  24. * const l2 = [{a: 1}, {a: 4}];
  25. * R.unionWith(R.eqBy(R.prop('a')), l1, l2); //=> [{a: 1}, {a: 2}, {a: 4}]
  26. */
  27. var unionWith =
  28. /*#__PURE__*/
  29. _curry3(function unionWith(pred, list1, list2) {
  30. return uniqWith(pred, _concat(list1, list2));
  31. });
  32. export default unionWith;