Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Consider the following code:
def first = ['a', 'B', 'c', 'd'] def second = ['b', 'C', 'd', 'e'] def lower = { one, two -> one.toLowerCase() <=> two.toLowerCase() } assert first.intersect(second) == ['d'] assert first.intersect(second, lower) == ['b', 'C', 'd'] assert second.intersect(first, lower) == ['B', 'c', 'd']
In most languages (e.g. Haskell, C#, PureScript) the result shown for the last two lines are reversed. The elements in the result are drawn from the first operand which match according to the comparator with an element in the second. For identity comparators they will be the same result but for the more unusual case of a projecting comparator (as shown here), Groovy is drawing elements from the second operand. This issue is to reverse that behavior as a breaking change for Groovy 4 only.