I am a newbie in Scala and would appreciate any direction or help in solving the following problem.
Input
I have a Map[String, Array[Double]]
that looks like follow:
Map(foo -> Array(12, 25, 100), bar -> Array(0.1, 0.001))
The Map can contain between 1 and 10 keys (depends on the some parameters in my application).
Processing
I would like to apply a cartesian product between the arrays of all keys and generate a structure that contains all the possible combinations of all values of all arrays.
In the example above, the cartesian product will create 3x2=6
different combinations: (12, 0.1), (12, 0.001), (25, 0.1), (25, 0.01), (100,0.1) and (100, 0.01)
.
For the sake of another example, in some cases I might have three key: the first key has an Array of 4 values, the second has an Array of 5 values and the third has an Array of 3 values, in this case the product has to generate 4x5x3=60
different combinations.
Desired output
Something like:
Map(config1 -> (foo -> 12, bar -> 0.1), config2 -> (foo -> 12, bar -> 0.001), config3 -> (foo -> 25, bar -> 0.1), config4 -> (foo -> 25, bar -> 0.001), config5 -> (foo -> 100, bar -> 0.1), config6 -> (foo -> 100, bar -> 0.001))