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
1.2 KiB

4 years ago
  1. import _curry3 from "./internal/_curry3.js";
  2. import concat from "./concat.js";
  3. import differenceWith from "./differenceWith.js";
  4. /**
  5. * Finds the set (i.e. no duplicates) of all elements contained in the first or
  6. * second list, but not both. Duplication is determined according to the value
  7. * returned by applying the supplied predicate to two list elements.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.19.0
  12. * @category Relation
  13. * @sig ((a, a) -> Boolean) -> [a] -> [a] -> [a]
  14. * @param {Function} pred A predicate used to test whether two items are equal.
  15. * @param {Array} list1 The first list.
  16. * @param {Array} list2 The second list.
  17. * @return {Array} The elements in `list1` or `list2`, but not both.
  18. * @see R.symmetricDifference, R.difference, R.differenceWith
  19. * @example
  20. *
  21. * const eqA = R.eqBy(R.prop('a'));
  22. * const l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}];
  23. * const l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}];
  24. * R.symmetricDifferenceWith(eqA, l1, l2); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
  25. */
  26. var symmetricDifferenceWith =
  27. /*#__PURE__*/
  28. _curry3(function symmetricDifferenceWith(pred, list1, list2) {
  29. return concat(differenceWith(pred, list1, list2), differenceWith(pred, list2, list1));
  30. });
  31. export default symmetricDifferenceWith;