Closed
Description
For latest proposed / accepted API, please see comment.
Background and motivation - UPDATED 2024/01/31
So that Enumerable.Range can be used with anything that implements IBinaryInteger<T>
.
API Proposal
public static class Enumerable
{
public static IEnumerable<T> Range<T>(T start, int count) where T : IBinaryInteger<T>
}
API Usage
public record struct MyInterval<T> where T : IBinaryInteger<T>
{
public T Start { get; }
public T End { get; }
// ...
public IEnumerable<T> GetAll() => Enumerable.Range(Start, End);
Alternative Designs
An alternative could be to handle all INumber<T>
, in this case having a 3rd increment parameter could be reasonable
public static class Enumerable
{
public static IEnumerable<T> Range<T>(T start, T end, T increment) where T : INumber<T>
}
Risks
The original proposal with 2 parameters overload for the Range
method could be source-breaking, as the following case returns an IEnumerable<int>
and not IEnumerablem<byte>
today:
byte start = 0, count = 5;
IEnumerable<int> e = Enumerable.Range(start, count);