有没有方法或一些聪明的方法,很容易阅读,使Groovy中的元素成为combination?我知道Iterable#combinations
或GroovyCollections#combinations
,但它使得部分排列重复据我了解到目前为止。看例子。Groovy中的真实组合
// 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
随意张贴替代解决方案。我仍然在寻找更好的可读性(它在脚本中用于非开发人员)和性能(没有不必要的迭代)。
谢谢。就一件事。你甚至不必测试!= b cos这个条件包含在 2014-10-09 08:57:24
这是真的,编辑它。谢谢。 – Kaffeleif 2014-10-09 09:04:34