How to iterate all combinations of List<List<T>>
<p>I have a <code>List&lt;List&lt;T&gt;&gt;</code> the length of both list dimensions varies.<br>
<a href="https://stackoverflow.com/questions/17192796/generate-all-combinations-from-multiple-lists">Using recursion I can calculate all the combinations</a></p>

<p>Some example <code>List&lt;List&lt;T&gt;&gt;</code> and their combinations</p>

<pre><code>[
 [1],
 [2, 3],
 [4, 5, 6]
] 
// [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 3, 4], [1, 3, 5], [1, 3, 6]

[ 
 [0, 4],
 [3, 4, 1, 2]
]
// [0, 3], [0, 4], [0, 1], [0, 2], [4, 3], [4, 4], [4, 1], [4, 2]

[ 
 ["A", "B", "B"],
 ["C"]
]
// ["A", "C"], ["B", "C"], ["B, "C"]
</code></pre>

<p>The amount of combinations can grow rapidly and using recursion becomes a memory and performance issue.<br>
How can I implement an iterator to iterate through the combinations as they are calculated?</p>

<p>Doing some reading I might be able to use a factorial or combinatorial number system, but im not sure how I would apply it in this situation.</p>