Remove duplicate items in Algebra.prototype.getUnion()
Given an algebra:
set.props.id("id")
and these two sets:
{ type: 'a' }
{ area: 'x' }
And these two lists related to the respective sets:
[{ id: 1, type: 'a' area: 'x' }, { id: 2, type: 'a', area: 'y' }]
[{ id: 1, type: 'a' area: 'x' }, { id: 3, type: 'b', area: 'x' }]
Previously, the result of getUnion()
would return a simple concatenation of these two lists:
[{ id: 1, type: 'a' area: 'x' }, { id: 2, type: 'a', area: 'y' }, { id: 1, type: 'a' area: 'x' }, { id: 3, type: 'b', area: 'x' }]
This is suboptimal in cases like in can-connect's cache-requests behavior, where the union of several sets may be used to build a query response for yet a different set. Each item should be represented at most once when creating the union. With this release, items in both aItems
and bItems
are removed from the bItems
before concatenating into a union result. The example above becomes:
[{ id: 1, type: 'a' area: 'x' }, { id: 2, type: 'a', area: 'y' }, { id: 3, type: 'b', area: 'x' }]
Note: this doesn't remove all duplicates, just removes duplicates from
bItems
that are already inaItems
-- ifaItems
already has a duplicate, orbItems
has a duplicate not inaItems
, it will be preserved.