Looking for a type of iterator that does this

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.

1 Like
fn apply<T>(s: &[T]) -> Vec<&[T]> {
    s.windows(2).collect()
}
2 Likes

Gonna give Krishna the solution, but asymmetrikon my heart

Thanks guys!