MoreLINQ icon indicating copy to clipboard operation
MoreLINQ copied to clipboard

[Proposal] EquiInterleave

Open Orace opened this issue 6 years ago • 1 comments

Like EquiZip, EquiInterleave throw if input sequences differ in size.

Orace avatar Nov 13 '19 21:11 Orace

What does {1, 2}.EquiInterleave({3}) should yield ?

  • 1, 3, 2, exception
  • 1, 3, exception

Orace avatar Nov 13 '19 21:11 Orace

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.

atifaziz avatar Jan 20 '23 23:01 atifaziz