pub struct Fold<S, A> { /* private fields */ }Expand description
A read-only multi-focus optic.
Like a Traversal but without the ability to modify.
Implementations§
Source§impl<S, A> Fold<S, A>
impl<S, A> Fold<S, A>
pub fn new(fold_fn: impl Fn(&S) -> Vec<A> + 'static) -> Fold<S, A>
pub fn get_all(&self, s: &S) -> Vec<A>
Sourcepub fn fold_map<R>(&self, s: &S, f: impl Fn(A) -> R) -> Rwhere
R: Monoid,
pub fn fold_map<R>(&self, s: &S, f: impl Fn(A) -> R) -> Rwhere
R: Monoid,
Map each focus to a monoid value and combine them.
Sourcepub fn any(&self, s: &S, f: impl Fn(&A) -> bool) -> bool
pub fn any(&self, s: &S, f: impl Fn(&A) -> bool) -> bool
Check if any focus satisfies a predicate.
Sourcepub fn all(&self, s: &S, f: impl Fn(&A) -> bool) -> bool
pub fn all(&self, s: &S, f: impl Fn(&A) -> bool) -> bool
Check if all foci satisfy a predicate.
Sourcepub fn find(&self, s: &S, f: impl Fn(&A) -> bool) -> Option<A>
pub fn find(&self, s: &S, f: impl Fn(&A) -> bool) -> Option<A>
Find the first focus satisfying a predicate.
Sourcepub fn then<B>(self, inner: Fold<A, B>) -> ComposedFold<S, B>where
S: 'static,
A: 'static,
B: 'static,
pub fn then<B>(self, inner: Fold<A, B>) -> ComposedFold<S, B>where
S: 'static,
A: 'static,
B: 'static,
Compose with another fold for deeper read-only access.
Trait Implementations§
Auto Trait Implementations§
impl<S, A> !RefUnwindSafe for Fold<S, A>
impl<S, A> !Send for Fold<S, A>
impl<S, A> !Sync for Fold<S, A>
impl<S, A> !UnwindSafe for Fold<S, A>
impl<S, A> Freeze for Fold<S, A>
impl<S, A> Unpin for Fold<S, A>
impl<S, A> UnsafeUnpin for Fold<S, A>
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