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]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With