(Un)Zip with variable input-/output-count

Download

UnZip is completely patched and I wonder if there is a better/faster way to create the spreads:
image

Zip uses the following helper method which seems to be rather fast:

public static IEnumerable<T> Interleave<T>(this IEnumerable<IEnumerable<T>> source)
{
    var queues = source.Select(x => new Queue<T>(x)).ToList();
    while (queues.Any(x => x.Any()))
    {
        foreach (var queue in queues.Where(x => x.Any()))
        {
            yield return queue.Dequeue();
        }
    }
}

sauce

1 Like

This is now part of VL.Addons.

3 Likes