Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of intersect in groovy collections

Tags:

what would be the opposite of intersect in groovy collections?

like image 670
Espen Schulstad Avatar asked Apr 19 '11 08:04

Espen Schulstad


1 Answers

You probably want to combine both the answers from @Andre and @denis

I think what you want is the union and then subtract the intersection from this

def a = [1,2,3,4,5] def b = [2,3,4]  assert [1,5] == ( a + b ) - a.intersect( b ) 

The solution given by denis would depend on whether you do

def opposite = leftCollection-rightCollection // [1,5] 

or

def opposite = rightCollection-leftCollection // [] 

which I don't think you wanted

like image 193
tim_yates Avatar answered Dec 01 '22 17:12

tim_yates