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

iter::repeat(copy_value).take(n) => repeat_n(copy_value, n) #13271

Open
leonardo-m opened this issue Aug 15, 2024 · 0 comments · May be fixed by #13858
Open

iter::repeat(copy_value).take(n) => repeat_n(copy_value, n) #13271

leonardo-m opened this issue Aug 15, 2024 · 0 comments · May be fixed by #13858
Labels
A-lint Area: New lints

Comments

@leonardo-m
Copy link

What it does

Once repeat_n has being stabilized, it suggests to replace repeat+take with repeat_n in some simple cases.

Advantage

Shorter code, less tokens for the programmer mind.

Drawbacks

I can't think any.

Example

#![feature(iter_repeat_n)]
use std::iter;
fn main() {
    for x in iter::repeat(10).take(3) {
        print!("{x} ");
    }
    println!();
}

Could be written as:

#![feature(iter_repeat_n)]
use std::iter;
fn main() {
    for x in iter::repeat_n(10, 3) {
        print!("{x} ");
    }
    println!();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant