-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Linqin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
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);MichalPetryka, colejohnson66, hez2010, Mrxx99, SommerEngineering and 9 moreSommerEngineering
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Linqin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged