pub struct IterableFoldFn<F>(pub F);Expand description
A wrapper that converts a function returning an iterable into a FoldFunc.
IterableFoldFn(f) where f: S -> impl IntoIterator<Item = A> implements
FoldFunc<S, A> by iterating over f(s) and folding with the monoid.
This avoids allocating an intermediate Vec<A> when the source is already
an iterable structure (e.g., a Vec<A>) or when a lazy iterator suffices.
§Type Parameters
F: The type of the inner function.
Tuple Fields§
§0: FTrait Implementations§
Source§impl<F: Clone> Clone for IterableFoldFn<F>
§Type Parameters
F: The type of the inner function.
impl<F: Clone> Clone for IterableFoldFn<F>
§Type Parameters
F: The type of the inner function.
Source§impl<'a, S, A, I, F> FoldFunc<'a, S, A> for IterableFoldFn<F>where
F: Fn(S) -> I,
I: IntoIterator<Item = A>,
§Type Parameters
'a: The lifetime of the function.
S: The source type of the structure.
A: The type of the focuses.
I: The iterable type returned by the function.
F: The type of the inner function.
impl<'a, S, A, I, F> FoldFunc<'a, S, A> for IterableFoldFn<F>where
F: Fn(S) -> I,
I: IntoIterator<Item = A>,
§Type Parameters
'a: The lifetime of the function.S: The source type of the structure.A: The type of the focuses.I: The iterable type returned by the function.F: The type of the inner function.
Source§fn apply<R: Monoid>(&self, f: impl Fn(A) -> R + 'a, s: S) -> R
fn apply<R: Monoid>(&self, f: impl Fn(A) -> R + 'a, s: S) -> R
§Type Signature
forall S A I R. (Monoid R, IntoIterator I) => (&IterableFoldFn S A I (S -> I), A -> R, S) -> R
§Type Parameters
R: The monoid type to fold into.
§Parameters
&self: The fold instance.f: The mapping function.s: The structure to fold.
§Returns
The combined monoid value.
§Examples
use fp_library::{
brands::optics::*,
classes::monoid::Monoid,
types::optics::{
FoldFunc,
IterableFoldFn,
},
};
let fold = IterableFoldFn(|v: Vec<i32>| v);
let result = fold.apply::<String>(|x| x.to_string(), vec![1, 2, 3]);
assert_eq!(result, "123".to_string());Auto Trait Implementations§
impl<F> Freeze for IterableFoldFn<F>where
F: Freeze,
impl<F> RefUnwindSafe for IterableFoldFn<F>where
F: RefUnwindSafe,
impl<F> Send for IterableFoldFn<F>where
F: Send,
impl<F> Sync for IterableFoldFn<F>where
F: Sync,
impl<F> Unpin for IterableFoldFn<F>where
F: Unpin,
impl<F> UnsafeUnpin for IterableFoldFn<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for IterableFoldFn<F>where
F: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more