let a = [0, 1, 2, 3, 4, 5, [...]]; // More generally, for any &[T]
let res = apply(&a);
assert_eq!([[0, 1], [1,2], [2,3], [3,4], [4,5]], res);
Is there an iterator that does exactly what apply
performs?
let a = [0, 1, 2, 3, 4, 5, [...]]; // More generally, for any &[T]
let res = apply(&a);
assert_eq!([[0, 1], [1,2], [2,3], [3,4], [4,5]], res);
Is there an iterator that does exactly what apply
performs?
(needing this for a recursive function)
This looks like the windows
iterator for slices.
fn apply<T>(s: &[T]) -> Vec<&[T]> {
s.windows(2).collect()
}
Gonna give Krishna the solution, but asymmetrikon my heart
Thanks guys!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.