I want to write a function which accepts a list of sequence in which each sequence will be used in for comprehension expression.
eg.
for (x <- (1 to 10); y <- (1 to 10)) yield List(x,y)
In the above expression, I must know before hand that I want a combination of x and y. WHat if I want a combination of x, y, z …etc… (an unknown number of combination)? If I want 10 combinations, I want to paste 10 snippets “x <- (1 to 10)” into the expression. I think I can do this with macro in Clojure (a way to paste code). How can I do this in Scala?
The function I want to write has the signature like this:
combine(list: List[List[Int]])
The body of the function will use each item in the list to paste into the for comprehension.
Hope you understand my intention.
If you want to compute the cartesian product of a list of lists, you can do it by chaining map and flatMap calls together recursively. That is what for expressions do anyway.