nyan icon indicating copy to clipboard operation
nyan copied to clipboard

Symmetric difference set operation

Open heinezen opened this issue 4 years ago • 1 comments

Symmetric difference, disjunctive union, XOR - or whatever you call it - is a set operation where the resulting set is composed of elements which are present in either set, but not in both. The corresponding python operator is ^=.

This operation would lower the required patches for "replacement" changes such as the replacement of a move ability.

Without XOR (2 patches):

PatchRemove<SomeUnit>(..):
    abilities -= {OldMove}

PatchAdd<SomeUnit>(..):
    abilities += {NewMove}

With XOR (1 patch):

PatchXOR<SomeUnit>(..)
    # OldMove will be removed because it is in both sets
    abilities ^= {OldMove, NewMove}

heinezen avatar Aug 31 '19 12:08 heinezen

We can add it, but I would be careful because if an unforseen mod already adds an ability you want to add know, the ^= will remove it then even though you intended to add it.

TheJJ avatar Aug 31 '19 14:08 TheJJ