mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-01 17:34:25 +02:00
Use .iter()
instead of (&values).into_iter()
(#2519)
The `(&values).into_iter()` construct used in the solution to the iterators exercise is kind of awkward and always gets questions from students. I think the better thing would be to use the `iter` method to get the initial iterator, as that's the more idiomatic way to. It's also an opportunity to point out that there are helper methods for getting an iterator for a collection.
This commit is contained in:
parent
c33a9b2ca4
commit
2e8d5d3d9c
@ -22,8 +22,8 @@
|
|||||||
/// Element `n` of the result is `values[(n+offset)%len] - values[n]`.
|
/// Element `n` of the result is `values[(n+offset)%len] - values[n]`.
|
||||||
fn offset_differences(offset: usize, values: Vec<i32>) -> Vec<i32> {
|
fn offset_differences(offset: usize, values: Vec<i32>) -> Vec<i32> {
|
||||||
// ANCHOR_END: offset_differences
|
// ANCHOR_END: offset_differences
|
||||||
let a = (&values).into_iter();
|
let a = values.iter();
|
||||||
let b = (&values).into_iter().cycle().skip(offset);
|
let b = values.iter().cycle().skip(offset);
|
||||||
a.zip(b).map(|(a, b)| *b - *a).collect()
|
a.zip(b).map(|(a, b)| *b - *a).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user