Groovy中的真正组合
发布时间:2020-12-14 16:29:09 所属栏目:大数据 来源:网络整理
导读:是否有方法或一些智能方法易于阅读,以便在Groovy中生成 combination个元素?我知道Iterable#组合或GroovyCollections#组合,但是到目前为止我对它进行了重复的部分排列.见例子. // Groovy combinations resultdef e = ['a','b','c']def result = [e,e].combin
是否有方法或一些智能方法易于阅读,以便在Groovy中生成
combination个元素?我知道Iterable#组合或GroovyCollections#组合,但是到目前为止我对它进行了重复的部分排列.见例子.
// Groovy combinations result def e = ['a','b','c'] def result = [e,e].combinations() assert [['a','a'],['b',['c',['a','b'],'c'],'c']] == result // What I'm looking for def e = ['a','c'] def result = ??? assert [['a','c']] == result
解决方法
我不太确定可读性,但这应该可以解决问题.
def e = ['a',e].combinations().findAll { a,b -> a < b } assert [['a','c']] == result 请注意,如果元素在列表中出现两次,则其组合也会出现两次.如果不需要,最后添加’.unique()’ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |