Say I have a data structure of IEnumerable> like this:
IEnumerable>
{ { A, B } { 1, 2, 3 } { Z } }
private static IEnumerable> GetAllCombinations(IEnumerable> a) { if (!a.Skip(1).Any()) { return a.First().Select(x => new[] { x }); } var tail = GetAllCombinations(a.Skip(1)).ToArray(); return a.First().SelectMany(f => tail.Select(x => new[] { f }.Concat(x))); }