MoreLINQ
MoreLINQ copied to clipboard
[Proposal] EquiInterleave
Like EquiZip, EquiInterleave throw if input sequences differ in size.
What does {1, 2}.EquiInterleave({3}) should yield ?
- 1, 3, 2, exception
- 1, 3, exception
This can be achieved relatively easily with EquiZip + SelectMany:
var xs =
from e in Enumerable.Range(1, 10)
.EquiZip(Enumerable.Range(11, 10), ValueTuple.Create)
from x in MoreEnumerable.Return(e.Item1)
.Append(e.Item2)
select x;
foreach (var x in xs)
Console.WriteLine(x);
Outputs:
1
11
2
12
3
13
4
14
5
15
6
16
7
17
8
18
9
19
10
20
Yes, it's never going to be as optimal as an operator implemented by hand, but I'm afraid I don't think it's common enough to warrant adding and maintaining a whole new operator along with its tests.
I'm happy to reconsider if it can be demonstrated to be extremely common in some field.