Alex Rivera | Logout

Opposite of intersect in groovy collections

Asked 2011-04-19T08:34:41.220
21

what would be the opposite of intersect in groovy collections?

Edit
Report

1 Answer

30

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

answered 2011-04-19T10:10:43.233

Your Answer