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

implement Trait std::iter::Step for BigInt #68

Open
iosmanthus opened this issue Nov 1, 2018 · 2 comments
Open

implement Trait std::iter::Step for BigInt #68

iosmanthus opened this issue Nov 1, 2018 · 2 comments

Comments

@iosmanthus
Copy link

Maybe it will be more convenient to write the following code after adding trait Step for BigInt:

for i in BigInt::from(1)..BigInt::from(1000) {
    // do something
}
@cuviper
Copy link
Member

cuviper commented Nov 1, 2018

std::iter::Step is still unstable, tracked in rust-lang/rust#42168.

That's a big reason why the num-iter crate exists, like its range function. But if your endpoints are small enough to fit in primitive types, like your example, it might actually be faster to just iterate that way and then convert: (1..1000).map(BigInt::from)

@Rudxain
Copy link

Rudxain commented May 7, 2024

If anyone reading this needs something like 0.. (RangeFrom trait), here you go:

std::iter::successors(Some(BigUint::zero()), |n| Some(n + 1u8))

I love successors because it's quite simple and flexible. It helped me refactor many loops into functional-style chains of data

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

Successfully merging a pull request may close this issue.

3 participants