pub struct Zipper<A> {
pub left: Vec<A>,
pub focus: A,
pub right: Vec<A>,
}Expand description
A zipper over a non-empty vector: models a focused list comonad.
The zipper is the canonical comonad for list-like structures: extract = current element, extend = apply f to each focus position.
Fields§
§left: Vec<A>§focus: A§right: Vec<A>Implementations§
Source§impl<A: Clone> Zipper<A>
impl<A: Clone> Zipper<A>
Sourcepub fn new(data: Vec<A>, i: usize) -> Option<Self>
pub fn new(data: Vec<A>, i: usize) -> Option<Self>
Create a zipper focused on index i of data.
Returns None if data is empty or i is out of bounds.
Sourcepub fn extend<B: Clone>(&self, f: impl Fn(&Zipper<A>) -> B) -> Zipper<B>
pub fn extend<B: Clone>(&self, f: impl Fn(&Zipper<A>) -> B) -> Zipper<B>
Extend the zipper comonad: apply f at every position.
This implements extend f w for the zipper comonad.
Sourcepub fn move_right(&self) -> Option<Zipper<A>>
pub fn move_right(&self) -> Option<Zipper<A>>
Move focus one step to the right.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
A zipper always has at least one element (the focus), so it is never empty.
Sourcepub fn is_singleton(&self) -> bool
pub fn is_singleton(&self) -> bool
Returns true if the zipper has only one element.
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for Zipper<A>where
A: Freeze,
impl<A> RefUnwindSafe for Zipper<A>where
A: RefUnwindSafe,
impl<A> Send for Zipper<A>where
A: Send,
impl<A> Sync for Zipper<A>where
A: Sync,
impl<A> Unpin for Zipper<A>where
A: Unpin,
impl<A> UnsafeUnpin for Zipper<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for Zipper<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more