I've seen this problem resolved for C# and other languages but not for Smalltalk. I have 3 collections, for example:
a := #(3 4 5).
b := #(4 1 2).
c := #(5 2 3).
and I need to make all possible combinations, i. e.:
#(3 4 5)
#(3 4 2)
#(3 4 3)
#(3 1 5)
#(3 1 2)
#(3 1 3)
#(3 2 5)
#(3 2 2)
#(3 2 3)
#(4 4 5)
...
I have seen in Squeak and Pharo there is combinations:atATimeDo: but I don't get how to use it for this case. This is not homework. Any help?
here is the code from Smalltalk/X's class library (in SequentialCollection). See the example-use comments at the end.
This is a bit cryptic, but short. It uses the block as an anonymous function (sort of, it still needs to be referenced from a variable so that it can be called recursively).
The purpose of combinations:atATimeDo: is to compute partitions of a given size.
To get the cartesian product, the recursive functional version provided by Martin Kobetic is the shortest code.
Here is an iterative variant: