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

Add LongSequence and LongRange #815

Closed
V0ldek opened this issue May 1, 2021 · 3 comments
Closed

Add LongSequence and LongRange #815

V0ldek opened this issue May 1, 2021 · 3 comments

Comments

@V0ldek
Copy link

V0ldek commented May 1, 2021

Neither standard LINQ nor MoreLINQ have a way of generating a sequence of Int64s. I've noticed that because I actually needed such a method. Obviously generating a sequence from 1 to 10^18 would kill anything you'd run that on, however I have use cases where I have to generate sequences of reasonable length but of large values.

I would like the following methods added:

IEnumerable<long> MoreEnumerable.LongRange(long from, long count);

IEnumerable<long> MoreEnumerable.LongSequence(long from, long to);

IEnumerable<long> MoreEnumerable.LongSequence(long from, long to, long step);

with obvious semantics identical to those of Enumerable.Range and MoreEnumerable.Sequence but for Int64.

If this was already considered but decided to not be implemented for MoreLINQ, let me know. If not I could implement a PR for these myself.

@atifaziz
Copy link
Member

atifaziz commented May 3, 2021

If this was already considered but decided to not be implemented for MoreLINQ

If memory serves right, no one has asked for it before.

If not I could implement a PR for these myself.

Since it's probably a very rare use case, wonder if it's even worth for you to go through the trouble of a PR and someone else having to maintain it. You could get away with using Generate that's already there:

var longs = MoreEnumerable.Generate(1L, x => checked(x + 1));

In fact, you could get away with pretty thin wrappers:

static class LongEnumerable
{
    public static IEnumerable<long> Range(long from, long count) =>
        Sequence(from, checked(from + count - 1), 1);

    public static IEnumerable<long> Sequence(long from, long to, long step) =>
        MoreEnumerable.Generate(from, x => checked(x + step))
                      .TakeWhile(x => x <= to);
}

@V0ldek
Copy link
Author

V0ldek commented May 4, 2021

Since it's probably a very rare use case, wonder if it's even worth for you to go through the trouble of a PR and someone else having to maintain it.

Yup, not sure about that either. Your wrappers are actually better than what I used before, so thanks.

I don't know what's the triage process in this repo, how do you decide what to add to the API? My guess would be to leave this issue hanging and see if someone else needs this use case.

@atifaziz
Copy link
Member

atifaziz commented May 5, 2021

Your wrappers are actually better than what I used before, so thanks.

Glad to hear they helped!

I don't know what's the triage process in this repo, how do you decide what to add to the API?

Nothing officially documented yet, but apart from one or two exceptions, the criteria that I've been using for a very long time now is that an extension/method has to do some non-trivial amount of work (and do it efficiently while maintaining correctness).

My guess would be to leave this issue hanging and see if someone else needs this use case.

If you don't mind, I'll close it as we have enough open issues, people can search across closed issues and keeping it open doesn't prevent from duplicates getting opened anyway.

If you do end up using Generate for long values then an example would be a welcomed contribution.

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

No branches or pull requests

2 participants