pub struct Fold<'a, PointerBrand, S, T, A, B, F>where
PointerBrand: UnsizedCoercible,
F: FoldFunc<'a, S, A>,
S: 'a,
T: 'a,
A: 'a,
B: 'a,{
pub fold_fn: F,
/* private fields */
}Expand description
A polymorphic fold.
Matches PureScript’s Fold r s t a b.
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure.A: The source type of the focus.B: The target type of the focus.F: The type of the fold function.
Fields§
§fold_fn: FThe fold function.
Implementations§
Source§impl<'a, PointerBrand, S, T, A, B, F> Fold<'a, PointerBrand, S, T, A, B, F>where
PointerBrand: UnsizedCoercible,
F: FoldFunc<'a, S, A>,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
S: The source type of the structure.
T: The target type of the structure.
A: The source type of the focus.
B: The target type of the focus.
F: The type of the fold function.
impl<'a, PointerBrand, S, T, A, B, F> Fold<'a, PointerBrand, S, T, A, B, F>where
PointerBrand: UnsizedCoercible,
F: FoldFunc<'a, S, A>,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure.A: The source type of the focus.B: The target type of the focus.F: The type of the fold function.
Sourcepub fn new(fold_fn: F) -> Self
pub fn new(fold_fn: F) -> Self
Create a new polymorphic fold.
§Type Signature
forall PointerBrand S T A B F. (UnsizedCoercible PointerBrand, FoldFunc F) => F -> Fold PointerBrand S T A B F
§Parameters
fold_fn: The fold function.
§Returns
A new instance of the type.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
types::optics::{
Fold,
IterableFoldFn,
},
};
let f: Fold<RcBrand, Vec<i32>, Vec<i32>, i32, i32, _> =
Fold::new(IterableFoldFn(|v: Vec<i32>| v));
assert_eq!(f.to_vec(vec![1, 2]), vec![1, 2]);Sourcepub fn to_vec(&self, s: S) -> Vec<A>where
A: Clone,
pub fn to_vec(&self, s: S) -> Vec<A>where
A: Clone,
Collect all the focuses of the fold into a Vec.
§Type Signature
forall PointerBrand S T A B F. (UnsizedCoercible PointerBrand, FoldFunc F) => (&Fold PointerBrand S T A B F, S) -> Vec A
§Parameters
&self: The fold instance.s: The structure to fold.
§Returns
A Vec containing all the focuses.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
types::optics::{
Fold,
IterableFoldFn,
},
};
let f: Fold<RcBrand, Vec<i32>, Vec<i32>, i32, i32, _> =
Fold::new(IterableFoldFn(|v: Vec<i32>| v));
assert_eq!(f.to_vec(vec![1, 2, 3]), vec![1, 2, 3]);Trait Implementations§
Source§impl<'a, PointerBrand, S, T, A, B, F> Clone for Fold<'a, PointerBrand, S, T, A, B, F>
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
S: The source type of the structure.
T: The target type of the structure.
A: The source type of the focus.
B: The target type of the focus.
F: The type of the fold function.
impl<'a, PointerBrand, S, T, A, B, F> Clone for Fold<'a, PointerBrand, S, T, A, B, F>
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure.A: The source type of the focus.B: The target type of the focus.F: The type of the fold function.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall PointerBrand S T A B F. (UnsizedCoercible PointerBrand, FoldFunc F) => &Fold PointerBrand S T A B F -> Fold PointerBrand S T A B F
§Returns
A new Fold instance that is a copy of the original.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
types::optics::{
Fold,
IterableFoldFn,
},
};
let f: Fold<RcBrand, Vec<i32>, Vec<i32>, i32, i32, _> =
Fold::new(IterableFoldFn(|v: Vec<i32>| v));
let cloned = f.clone();
assert_eq!(cloned.to_vec(vec![1, 2]), vec![1, 2]);1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, PointerBrand, S, T, A, B, F> FoldOptic<'a, S, A> for Fold<'a, PointerBrand, S, T, A, B, F>where
PointerBrand: UnsizedCoercible,
F: FoldFunc<'a, S, A> + Clone + 'a,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
S: The source type of the structure.
T: The target type of the structure.
A: The source type of the focus.
B: The target type of the focus.
F: The type of the fold function.
impl<'a, PointerBrand, S, T, A, B, F> FoldOptic<'a, S, A> for Fold<'a, PointerBrand, S, T, A, B, F>where
PointerBrand: UnsizedCoercible,
F: FoldFunc<'a, S, A> + Clone + 'a,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure.A: The source type of the focus.B: The target type of the focus.F: The type of the fold function.
Source§fn evaluate<R: 'a + Monoid + 'static, Q: UnsizedCoercible + 'static>(
&self,
pab: <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, A, A>,
) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate<R: 'a + Monoid + 'static, Q: UnsizedCoercible + 'static>( &self, pab: <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall PointerBrand S T A B F R Q. (Monoid R, UnsizedCoercible Q, UnsizedCoercible PointerBrand, FoldFunc F) => (&Fold PointerBrand S T A B F, Forget Q R A A) -> Forget Q R S S
§Type Parameters
R: The monoid type.Q: The reference-counted pointer type for the Forget brand.
§Parameters
&self: The fold instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
functions::*,
types::optics::*,
};
let f_optic: Fold<RcBrand, Vec<i32>, Vec<i32>, i32, i32, _> =
Fold::new(IterableFoldFn(|v: Vec<i32>| v));
let f = Forget::<RcBrand, String, i32, i32>::new(|x: i32| x.to_string());
let folded: Forget<RcBrand, String, Vec<i32>, Vec<i32>> = FoldOptic::evaluate(&f_optic, f);
assert_eq!(folded.run(vec![1, 2, 3]), "123".to_string());Auto Trait Implementations§
impl<'a, PointerBrand, S, T, A, B, F> Freeze for Fold<'a, PointerBrand, S, T, A, B, F>where
F: Freeze,
impl<'a, PointerBrand, S, T, A, B, F> RefUnwindSafe for Fold<'a, PointerBrand, S, T, A, B, F>where
F: RefUnwindSafe,
PointerBrand: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<'a, PointerBrand, S, T, A, B, F> Send for Fold<'a, PointerBrand, S, T, A, B, F>
impl<'a, PointerBrand, S, T, A, B, F> Sync for Fold<'a, PointerBrand, S, T, A, B, F>
impl<'a, PointerBrand, S, T, A, B, F> Unpin for Fold<'a, PointerBrand, S, T, A, B, F>
impl<'a, PointerBrand, S, T, A, B, F> UnsafeUnpin for Fold<'a, PointerBrand, S, T, A, B, F>where
F: UnsafeUnpin,
impl<'a, PointerBrand, S, T, A, B, F> UnwindSafe for Fold<'a, PointerBrand, S, T, A, B, F>where
F: UnwindSafe,
PointerBrand: UnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
A: RefUnwindSafe,
B: RefUnwindSafe,
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
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>
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>
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