There are a number of threads on the internet discussing performant ways of picking subsets out of a List or a Set in java / groovy. As I could not find any answers which felt clean to me, I did a bit of research and found the apache commons math Combinations class which seems quite performant, exists in mavenCentral and offers a clean interface.
For a random reference, picking sets of 10 from a list of 30 (about 30M combinations) takes about 500ms on my workhorse machine which is more or less up to date. That is just the apache commons piece which only gives back the indicies into the source (i.e. it sends out sets [1,2], [1,3], [2,3] if you tell it to pick 2 out of a set of 3, you can not ask it for subsets of length 2 for list ['a', 'b', 'c']) list/set.
In the below code we add the ability to work directly with lists and ask for subsets in groovy which means a performance hit, but I would guess that the convenience is in most cases worth the loss in performance.
I'm posting this in