Enumerable.Repeat should have an overload with the following signature:
public static System.Collections.Generic.IEnumerable
The behavior would be repeating the value infinitely to allow composing lazy sequences without having to provide int.MaxValue or similar workarounds (which have the obvious limitation of having a bound).
~cs
static class Example
{
public static IEnumerable
.Select((num, shift) => num >> shift)
.TakeWhile(x => x != 0)
.Select(x => (x & 1) == 1);
}
~
As rather uncommon usecase I think this shouldn't get into corefx.
But you can write such a method quite simple:
c#
public static IEnumerable<T> RepeatEndless<T>(T element)
{
while (true)
{
yield return element;
}
}
BTW: see API Review Process
I think the less common use case is actually the Repeat(x, y), because it's a special case of Repeat(x) as the former could be implemented with idiomatic LINQ:
~cs
var _ = Enumerable.Repeat(x).Take(y);
~
Of course it is trivial to implement it with a generator, but that breaks the flow of a functional style C# program.
Most helpful comment
As rather uncommon usecase I think this shouldn't get into corefx.
But you can write such a method quite simple:
c# public static IEnumerable<T> RepeatEndless<T>(T element) { while (true) { yield return element; } }BTW: see API Review Process