Skip to content

Instantly share code, notes, and snippets.

@droyad
Created August 11, 2015 03:09
Show Gist options
  • Save droyad/a778b4ba1ebc298d4100 to your computer and use it in GitHub Desktop.
Save droyad/a778b4ba1ebc298d4100 to your computer and use it in GitHub Desktop.
void Main()
{
var items = new [] {
new[] {"A", "B"},
new[] {"1", "2", "3"},
new[] {"*", "+"}
};
//items.Aggregate((memo, i) => memo.SelectMany (m => i.Concat(new[]{ m}).ToArray()).ToArray()).Dump();
var currentList = new List<List<string>>(items[0].Select (i => new List<string> { i}));
foreach(var genArg in items.Skip(1))
{
var newList = new List<List<string>>();
foreach(var currentItem in currentList)
foreach(var newThing in genArg)
{
var newItem = new List<string>(currentItem);
newItem.Add(newThing);
newList.Add(newItem);
}
currentList = newList;
}
currentList.Dump();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment