I have seen solutions like this to zip
at compile time a known number of List
s greater than two List
s:
public static class MyFunkyExtensions
{
public static IEnumerable<TResult> ZipThree<T1, T2, T3, TResult>(
this IEnumerable<T1> source,
IEnumerable<T2> second,
IEnumerable<T3> third,
Func<T1, T2, T3, TResult> func)
{
using (var e1 = source.GetEnumerator())
using (var e2 = second.GetEnumerator())
using (var e3 = third.GetEnumerator())
{
while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext())
yield return func(e1.Current, e2.Current, e3.Current);
}
}
}
What is the correct code if you have a List<List<>>
and you want to dynamically zip them? NOTE that the number of Lists is unknown at compile time. I don't want to have to create a ZipFour, ZipFive etc...
>` but with the zipped values (kind of pivoted, I guess)?
– ProgrammingLlama Apr 16 '19 at 02:30