A bit of collection magic
Hi list, I'd love to have something like: #(#a #b) combinationsWith: #('one' 'two' 'three') collect: [:i :j | i , ' matches ' , j asString] That returns the collection: #('a matches one' 'a matches two' 'a matches three' 'b matches one' 'b matches two' 'b matches three') In other words, is there some kind of vectorial-product-like method for collections in Smalltalk? Thanks! Cheers, -- Bernat Romagosa.
I normally do this with two nested #do: calls: Array streamContents: [:stream | #(a b) do: [: i | #('one' 'two' 'three') do: [:j | stream nextPut: (i , ' matches ' , j asString)]]]. However, it may well be that there some method like this in Pharo or some external package on SqueakSource. Cheers, Bernhard Am 07.07.2011 um 12:02 schrieb Bernat Romagosa:
Hi list,
I'd love to have something like:
#(#a #b) combinationsWith: #('one' 'two' 'three') collect: [:i :j | i , ' matches ' , j asString]
That returns the collection:
#('a matches one' 'a matches two' 'a matches three' 'b matches one' 'b matches two' 'b matches three')
In other words, is there some kind of vectorial-product-like method for collections in Smalltalk?
Thanks!
Cheers,
-- Bernat Romagosa.
participants (2)
-
Bernat Romagosa -
Bernhard Pieber