[ 
https://issues.apache.org/jira/browse/GROOVY-11127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17743589#comment-17743589
 ] 

ASF GitHub Bot commented on GROOVY-11127:
-----------------------------------------

paulk-asert commented on PR #1915:
URL: https://github.com/apache/groovy/pull/1915#issuecomment-1637221541

   @eric-milles Just some notes about historical feature requests/discussions 
(which we can re-evaluate if we think they no longer hold but shouldn't totally 
ignore):
   
   - Folks asked us to retain the sorted nature of sets for as many operators 
as possible which is why there are 48 existing DGM methods which follow that 
pattern.
   - Folks using Groovy operators on heterogeneous data very much like 
`NumberAwareComparator` but in some data science scenarios with homogeneous 
data, folks didn't want the performance hit. That's why I asked for those 
methods to be added. But I note that while we previously added that capability 
for `intersect` and `minus` we don't currently have it for `plus` (though we 
probably should).
   - There have also been numerous discussions on commutativity in the past. We 
don't expect commutativity for normal method calls, e.g. `List#add(String)` 
isn't the same as `String#add(List)` but for operators there is a higher 
expectation that commutativity will hold. But even for mathematical operators, 
minus isn't commutative for instance. So, we while it has been a desirable 
feature for operators, we haven't had a strict requirement to always support 
commutativity. Do a search on "commutativity" on markmail (or elsewhere) and 
you will see numerous discussions.




> Add '|', '&', and '^' operators to Set and SortedSet
> ----------------------------------------------------
>
>                 Key: GROOVY-11127
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11127
>             Project: Groovy
>          Issue Type: New Feature
>          Components: groovy-jdk
>            Reporter: Spencer Allain
>            Priority: Trivial
>             Fix For: 5.x
>
>
> Many languages conventionally allow sets to use '|' as union, '&' as 
> intersection, and '^' as symmetric difference operations on sets.
> This ticket is proposing adding these operations as DefaultGroovyMethods for 
> Set and SortedSet such that the below tests should pass:
> {code:java}
> Set a = [1,2,3,4] as Set
> Set b = [3,4,5,6] as Set
> assert (a | b) == [1,2,3,4,5,6] as Set
> assert (a & b) == [3,4] as Set
> assert (a ^ b) == [1,2,5,6] as Set
> Set d = ['a', 'B', 'c'] as Set
> Set e = ['A', 'b', 'D'] as Set
> assert d.and(e, String.CASE_INSENSITIVE_ORDER) == ['a', 'B'] as Set
> assert d.and(e, Comparator.naturalOrder()) == [] as Set
> assert d.xor(e, String.CASE_INSENSITIVE_ORDER) == ['c', 'D'] as Set
> assert d.xor(e, Comparator.naturalOrder()) == ['a', 'B', 'c', 'A', 'b', 'D'] 
> as Set
> {code}
> A  [Pull Request|https://github.com/apache/groovy/pull/1915] exists that 
> implements the desired additions for the 5.x groovy branch (master), but it 
> should be fairly easy to make the functionality available in 4.x if desired.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to