Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Sequence for any number type #892

Closed
atifaziz opened this issue Nov 19, 2022 · 0 comments · Fixed by #893
Closed

Generic Sequence for any number type #892

atifaziz opened this issue Nov 19, 2022 · 0 comments · Fixed by #893
Assignees
Milestone

Comments

@atifaziz
Copy link
Member

atifaziz commented Nov 19, 2022

I propose to add a generic version of Sequence for any number type:

public static IEnumerable<T> Sequence<T>(T start, T stop, T step)
    where T : INumber<T> =>
    Generate(start, n => n + step).TakeWhile(n => step >= T.Zero ? stop >= n : stop <= n);

It would address requests like #815 without having to maintain duplicate versions. However, using static abstract members means this will be available .NET 7+ onwards only. The fallback for other versions would still be to go with Generate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant