You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2021/10/01 22:22:00 UTC

[jira] [Resolved] (GROOVY-10275) Align intersect which takes a closure/comparator ordering to be the same as other languages.

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

Paul King resolved GROOVY-10275.
--------------------------------
    Fix Version/s: 4.0.0-beta-2
         Assignee: Paul King
       Resolution: Fixed

> 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.3.4#803005)