本文介绍了Groovy中有Scala'zip'函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Scala中,我可以写下如下内容: $ $ p $ $ $ $ $ $ $ a $ List $($ 1 $ b val b = List(4,5) println(a zip b)
会产生 List((1,4),(2,5))作为输出。 现在我在Groovy中有两个集合,以类似的方式压缩它们。 Groovy的相当于Scala的 zip $ c $
c>是 列表#转换 ,可以在清单列表中调用: assert [[转置()== [[1,4],[2,5]]
In Scala I can write something like this:
val a = List(1, 2, 3) val b = List(4, 5) println(a zip b)That would produce List((1,4), (2,5)) as output. Now I have two collections in Groovy and want to zip them in similar fashion. What is the simplest way to do this?
解决方案Groovy's equivalent of Scala's zip is List#transpose, which can be called on a list of lists:
assert [[1, 2, 3], [4, 5]].transpose() == [[1, 4], [2, 5]]
更多推荐
Groovy中有Scala'zip'函数吗?
发布评论