groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Schalk Cronjé <ysb...@gmail.com>
Subject Shortest way of creating combinations of array elements
Date Thu, 12 Nov 2015 16:06:26 GMT
I am trying to find the shortest method of creating pairs of values from 
two lists.

    def a = [ 1,2,3,4,5,6 ]
    def b = [ 'a','b','c' ]

    assert [ [ 1,'a'], [2,'a'], ... [5,'c'],[6,'c'] == f(a,b)

The question is what te shortest possible implementation f(a,b) looks like.

I know a.collect { item -> b.collect { [item,it] }  } should work, but 
wondering if there is something better.

-- 
Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r


Mime
View raw message