Skip to content

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

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

Closed
leonardo-m opened this issue Aug 15, 2024 · 0 comments · Fixed by #13858
Closed

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

leonardo-m opened this issue Aug 15, 2024 · 0 comments · 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!();
}
@leonardo-m leonardo-m added the A-lint Area: New lints label Aug 15, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 19, 2025
…t_n()` (#13858)

close #13271

changelog: add new `manual_repeat_n` lint
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