[ 
https://issues.apache.org/jira/browse/GROOVY-10275?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King closed GROOVY-10275.
------------------------------

> Align intersect which takes a closure/comparator ordering to be the same as 
> other languages.
> --------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10275
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10275
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>              Labels: breaking
>             Fix For: 4.0.0-beta-2
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Consider the following code:
> {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']
> {code}
> 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.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to