Iterator chain
/// Calculate the differences between elements of `values` offset by `offset`, /// wrapping around from the end of `values` to the beginning. /// /// Element `n` of the result is `values[(n+offset)%len] - values[n]`. fn offset_differences<N>(offset: usize, values: Vec<N>) -> Vec<N> where N: Copy + std::ops::Sub<Output = N>, { // let len = values.len(); // values // .iter() // .enumerate() // .map(|(idx, &v)| values[(offset + idx) % len] - v) // .collect::<Vec<N>>() let a = (&values).into_iter(); let b = (&values).into_iter().cycle().skip(offset); a.zip(b).map(|(a, b)| *b -*a ).take(values.len()).collect() } 本作品采用《CC 协议》,转载必须注明作者和本文链接
关于 LearnKu