Skip to content

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

Closed
@leonardo-m

Description

@leonardo-m

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!();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions