Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: xor #363

Open
mwarger opened this issue Aug 21, 2023 · 2 comments · May be fixed by #368
Open

feature request: xor #363

mwarger opened this issue Aug 21, 2023 · 2 comments · May be fixed by #368

Comments

@mwarger
Copy link

mwarger commented Aug 21, 2023

I would love it if this library had methods analogous to xor from lodash (https://lodash.com/docs/4.17.15#xor).

@eranhirsch
Copy link
Collaborator

eranhirsch commented Aug 22, 2023

I think that's great, I already have an implementation in one of my projects, but I do have a problem with some of the semantics of the xor i'd like to get feedback on.

In lodash it does an implicit unique filtering of the input array, even when it's performed on a single array (xor([1,1,1]) => [1]). I think this is a mistake. Arrays are not sets, and there's no technical reason to do the uniquness, it's just semantics.

I think we should use multi-set semantics for arrays, basically meaning that multiple items can exist for the same value. Defining multisetDifference as the result of removing from A any items that exist in B (so for example: multisetDifference([1,1,1,2,2,3], [1,2]) => [1,1,2,3]) then xor would be defined as concat(multisetDifference(A, B), multisetDifference(B, A)) (so for example: xor([1,1,1,2,2,3], [1,2,4]) => concat([1,1,2,3], [4]) => [1,1,2,3,4]).

WDYT?

@mwarger
Copy link
Author

mwarger commented Aug 23, 2023

I agree regarding uniqueness - if one wants uniqueness they can explicitly do that before calling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants