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