Pseudo-RFC: Cursors (Reversible Iterators)

How would map interact with Cursors? I’d imagine proposal 1 requires replacing the FnMut closure with an Fn closure:

impl<B, I: Cursor, F> Cursor for Map<I, F> where
    F: Fn(I::Item) -> B 
{
    fn prev(&mut self) -> Option<A> {
        self.iter.prev()
    }
}
impl<B, I: DoubleEndedCursor, F> DoubleEndedCursor for Map<I, F> where
    F: Fn(I::Item) -> B
{
    fn prev_back(&mut self) -> Option<A> {
        self.iter.prev_back()
    }
}

It sounds doable, but interacts poorly with interior mutability, like maybe fn types or const Fn is more the goal, but w lack traits for those. Also, algorithms accessing a data structure this way sound rather niche. It’s more common algorithms want to repeatedly do the same or reverse iteration over some view of some data structure. We might address this with closure that return iterators, like FnBorrow traits

After this, algorithm want more powerful data structure access with specific properties, like random access, or certain insertion characteristics, or whatever. We could again wrap such properties inside views, but exactly how gets tricky. We could discuss some hierarchy of traits for specific data structure properties.

1 Like