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

Open
atifaziz opened this issue Nov 19, 2022 · 0 comments · May be fixed by #893
Open

Generic Sequence for any number type #892

atifaziz opened this issue Nov 19, 2022 · 0 comments · May be fixed by #893
Assignees

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.

@atifaziz atifaziz linked a pull request Nov 19, 2022 that will close this issue
@atifaziz atifaziz linked a pull request Nov 19, 2022 that will close this issue
@atifaziz atifaziz self-assigned this Nov 19, 2022
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