using System;
using System.Collections.Generic;
using System.Linq;
public class Test
{
public delegate void IntConsumer(List<int> ints);
public static void doStuff(List<List<int>> arrays, List<IntConsumer> consumers) {
processArrays(arrays, consumers, new List<int>());
}
private static void processArrays(List<List<int>> arrays, List<IntConsumer> consumers, List<int> consumerArgsSoFar) {
if(consumers.Count == 0 || arrays.Count == 0) {
return;
}
List<int> currentArray = arrays[0];
List<List<int>> remainingArrays = arrays.GetRange(1, arrays.Count-1);
IntConsumer currentConsumer = consumers[0];
List<IntConsumer> remainingConsumers = consumers.GetRange(1, arrays.Count-1);
if(currentArray.Count == 0) {
processArrays(remainingArrays, remainingConsumers, consumerArgsSoFar);
} else {
for(int i = 0; i < currentArray.Count; i++) {
List<int> consumerArgs = new List<int>(consumerArgsSoFar);
consumerArgs.Add(currentArray[i]);
currentConsumer(consumerArgs);
processArrays(remainingArrays, remainingConsumers, consumerArgs);
}
}
}
public static void log1(List<int> x) {
Console.WriteLine("log1");
x.ForEach(Console.Write);
Console.WriteLine();
}
public static void log2(List<int> x) {
Console.WriteLine("log2");
x.ForEach(Console.Write);
Console.WriteLine();
}
public static void log3(List<int> x) {
Console.WriteLine("log3");
x.ForEach(Console.Write);
Console.WriteLine();
}
public static void Main() {
List<int> dim1 = new List<int>(){10, 20, 30};
List<int> dim2 = new List<int>(){};
List<int> dim3 = new List<int>(){12, 22, 32};
List<List<int>> arrays = new List<List<int>>(){dim1, dim2, dim3};
List<IntConsumer> consumers = new List<IntConsumer>(){log1, log2, log3};
doStuff(arrays, consumers);
}
}