2

This is probably a silly question however, is there a simple way of doing antijoins of collections in Groovy?

I know there are [equivilent ways of doing unions and intersections].

My thought on how to do this is:

List a,b; 
union(a,b) - intersection(a,b) 

However, I'm not sure if there is a difference operator for collections in groovy.

monksy
  • 14,156
  • 17
  • 75
  • 124

2 Answers2

4

It turns out that can you can do a subtraction operation on 2 lists, and receive a list back of the disjoint collection. Just use the subtraction operator between two lists.

 listone - listtwo
monksy
  • 14,156
  • 17
  • 75
  • 124
1

Afaik, there isn't an operator our method to do this for you (might be a cool addition to groovy though)

The closest I can think of is the disjoint method which returns true if there is no intersection between lists, and false otherwise

tim_yates
  • 167,322
  • 27
  • 342
  • 338