public static IEnumerable<T> Interleave<T>(
this IEnumerable<T> sequence,
params IEnumerable<T>[] otherSequences
)
<ExtensionAttribute>
Public Shared Function Interleave(Of T) (
sequence As IEnumerable(Of T),
ParamArray otherSequences As IEnumerable(Of T)()
) As IEnumerable(Of T)
public:
[ExtensionAttribute]
generic<typename T>
static IEnumerable<T>^ Interleave(
IEnumerable<T>^ sequence,
... array<IEnumerable<T>^>^ otherSequences
)
[<ExtensionAttribute>]
static member Interleave :
sequence : IEnumerable<'T> *
otherSequences : IEnumerable<'T>[] -> IEnumerable<'T>
Interleave combines sequences by visiting each in turn, and returning the first element of each, followed by the second, then the third, and so on. So, for example:
var xs = new[] { 1, 1, 1 }.Interleave(new[] { 2, 2, 2 }, new[] { 3, 3, 3 });
// xs = { 1, 2, 3, 1, 2, 3, 1, 2, 3 }
This operator behaves in a deferred and streaming manner.
When sequences are of unequal length, this method will skip those sequences that have been fully consumed and continue interleaving the remaining sequences.
The sequences are interleaved in the order that they appear in the otherSequences collection, with sequence as the first sequence.