API Proposal: Generic LINQ Numeric Operators · Issue #64031 · dotnet/runtime (original) (raw)
Background and motivation
With the introduction of generic operators it's expected to be able to use LINQ over numeric sequences in a generic manner.
Additionally this can be considered for extensions on other list-like types.
Relates to #63732
API Proposal
namespace System.Linq { public static class Enumerable { public static T Sum(this IEnumerable source) where T : IAdditionOperators<T, T, T>, IAdditiveIdentity<T, T>; public static IEnumerable Range<T, TStep>(T start, T end, TStep step) where ...; public static T Min(this IEnumerable source) where T : ..; public static T Max(this IEnumerable source) where T : ..; // The result value is most likely floating-point. Should it be generic? // If so, is it possible for type inference to pick an appropriate type? public static T Average(this IEnumerable source) where T : ..; // .. } }
API Usage
IEnumerable numericSeq = e; T sum = numericSeq.Sum();
Alternative Designs
No response
Risks
No response