I am looking for a data type that is a mixture of a vector and an iterator, i.e. it should be
- like a vector in the sense that it allows for random access to all of its elements without advancing a index as in the
Iterator
case. - like an
Iterator
, it should be possible to.filter()
,.fold()
and.map()
the data-type lazily, i.e. the computation is only done then when the elements are actually accessed.
I hope that the pseudo-below helps to illustrate what I want
fn main() {
let x = vec![1, 2, 3];
let x1 = x.into_random_access_iter().map(|i| i ^ 2);
map.get(1) // 1
map.get(2) 4
map.get(1) // 1
let x2 = x1.filter(|i| i <= 4)
x2.len() // 2
}
So far, I was unable to find such a data type, but I might just be missing the correct terminology to express what I want.