Is there a way or some smart way that is easy to read to make a combination of elements in Groovy? I know Iterable#combinations or GroovyCollections#combinations , but it does partial permutation with repetition, as far as I understand it so far. See an example.
// Groovy combinations result def e = ['a', 'b', 'c'] def result = [e, e].combinations() assert [['a', 'a'], ['b', 'a'], ['c', 'a'], ['a', 'b'], ['b', 'b'], ['c', 'b'], ['a','c'], ['b', 'c'], ['c', 'c']] == result // What I'm looking for def e = ['a', 'b', 'c'] def result = ??? assert [['a', 'b'], ['a', 'c'], ['b', 'c']] == result
Feel free to post alternative solutions. I'm still looking for better readability (it is used in the script for non-developers) and performance (without unnecessary iterations).
source share