Let's say there are three collections:
val numbers = List("1", "2")
val signs = List("-", "+")
val chars = List("a", "b")
I want to generate combinations of elements of those collections. What I want is not exactly a cartesian product, nor all possible combinations. What I want to have is something like this:
(1)
(1, -)
(1, -, a)
(1, -, b)
(1, +)
(1, +, a)
(1, +, b)
...
If I could sum this up in a set of formulas, I want to have these sets:
numbers
signs
chars
numbers * signs
numbers * chars
signs * chars
numbers * signs * chars
with important note that each of the product can contain only one element from each of the sets. These tuples, for example, would not be something I want in my result:
(1, 2, -)
(a, -, +)
because they have two numbers or two signs.
Any hints on how I could approach this interesting problem?
I think Python package itertools has product
function that deals with this, but I could not find anything similar for Scala.