pub struct IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + 'a,{
pub fold_fn: F,
/* private fields */
}Expand description
A monomorphic indexed fold.
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The type of the structure.A: The type of the focus.F: The fold function type.
Fields§
§fold_fn: FThe fold function.
Implementations§
Source§impl<'a, PointerBrand, I, Brand, A> IndexedFoldPrime<'a, PointerBrand, I, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, A, Folded<Brand>>where
Brand: FoldableWithIndex<Index = I>,
A: 'a + Clone,
I: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The profunctor type.
I: The index type.
Brand: The brand of the foldable structure.
A: The type of the elements in the structure.
impl<'a, PointerBrand, I, Brand, A> IndexedFoldPrime<'a, PointerBrand, I, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, A, Folded<Brand>>where
Brand: FoldableWithIndex<Index = I>,
A: 'a + Clone,
I: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The profunctor type.I: The index type.Brand: The brand of the foldable structure.A: The type of the elements in the structure.
Sourcepub fn folded() -> Self
pub fn folded() -> Self
Create a monomorphic indexed fold from a FoldableWithIndex.
§Type Signature
forall PointerBrand I Brand A. FoldableWithIndex Brand => () -> IndexedFoldPrime PointerBrand I Brand A
§Returns
A new IndexedFoldPrime instance.
§Examples
use fp_library::{
brands::{
RcBrand,
VecBrand,
optics::*,
},
functions::optics_indexed_fold_map,
types::optics::{
Folded,
IndexedFoldPrime,
},
};
let l: IndexedFoldPrime<RcBrand, usize, Vec<i32>, i32, Folded<VecBrand>> =
IndexedFoldPrime::folded();
let v = vec![10, 20];
let s =
optics_indexed_fold_map::<RcBrand, _, _, _, String>(&l, |i, x| format!("{}:{}", i, x), v);
assert_eq!(s, "0:101:20".to_string());Source§impl<'a, PointerBrand, I, S, A, F> IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
I: The index type.
S: The type of the structure.
A: The type of the focus.
F: The fold function type.
impl<'a, PointerBrand, I, S, A, F> IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The type of the structure.A: The type of the focus.F: The fold function type.
Sourcepub fn new(fold_fn: F) -> Self
pub fn new(fold_fn: F) -> Self
Create a new monomorphic indexed fold.
§Type Signature
forall PointerBrand I S A F. IndexedFoldFunc F => F -> IndexedFoldPrime PointerBrand I S A F
§Parameters
fold_fn: The fold function.
§Returns
A new IndexedFoldPrime instance.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
classes::{
IndexedFoldOptic,
ToDynCloneFn,
monoid::Monoid,
semigroup::Semigroup,
},
types::optics::*,
};
#[derive(Clone)]
struct MyFold;
impl<'a> IndexedFoldFunc<'a, usize, Vec<i32>, i32> for MyFold {
fn apply<R: 'a + Monoid + 'static>(
&self,
f: Box<dyn Fn(usize, i32) -> R + 'a>,
s: Vec<i32>,
) -> R {
s.into_iter()
.enumerate()
.fold(R::empty(), |acc, (i, x)| Semigroup::append(acc, f(i, x)))
}
}
let l: IndexedFoldPrime<RcBrand, usize, Vec<i32>, i32, MyFold> = IndexedFoldPrime::new(MyFold);
let f = Forget::<RcBrand, String, (usize, i32), i32>::new(|(i, x)| format!("[{}]={}", i, x));
let pab = Indexed::new(f);
let result = IndexedFoldOptic::evaluate::<String, RcBrand>(&l, pab);
assert_eq!(result.run(vec![10, 20]), "[0]=10[1]=20");Trait Implementations§
Source§impl<'a, PointerBrand, I, S, A, F> Clone for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
I: The index type.
S: The type of the structure.
A: The type of the focus.
F: The fold function type.
impl<'a, PointerBrand, I, S, A, F> Clone for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The type of the structure.A: The type of the focus.F: The fold function type.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall PointerBrand I S A F. IndexedFoldFunc F => &IndexedFoldPrime PointerBrand I S A F -> IndexedFoldPrime PointerBrand I S A F
§Returns
A new IndexedFoldPrime instance that is a copy of the original.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
classes::{
IndexedFoldOptic,
ToDynCloneFn,
monoid::Monoid,
semigroup::Semigroup,
},
types::optics::*,
};
#[derive(Clone)]
struct MyFold;
impl<'a> IndexedFoldFunc<'a, usize, Vec<i32>, i32> for MyFold {
fn apply<R: 'a + Monoid + 'static>(
&self,
f: Box<dyn Fn(usize, i32) -> R + 'a>,
s: Vec<i32>,
) -> R {
s.into_iter()
.enumerate()
.fold(R::empty(), |acc, (i, x)| Semigroup::append(acc, f(i, x)))
}
}
let l: IndexedFoldPrime<RcBrand, usize, Vec<i32>, i32, MyFold> = IndexedFoldPrime::new(MyFold);
let cloned = l.clone();
let f = Forget::<RcBrand, String, (usize, i32), i32>::new(|(i, x)| format!("[{}]={}", i, x));
let pab = Indexed::new(f);
let result = IndexedFoldOptic::evaluate::<String, RcBrand>(&cloned, pab);
assert_eq!(result.run(vec![10, 20]), "[0]=10[1]=20");1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a, F> IndexedFoldOptic<'a, I, S, A> for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
I: The index type.
S: The type of the structure.
A: The type of the focus.
F: The fold function type.
impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a, F> IndexedFoldOptic<'a, I, S, A> for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The type of the structure.A: The type of the focus.F: The fold function type.
Source§fn evaluate<R: 'a + Monoid + 'static, Q: ToDynCloneFn + 'static>(
&self,
pab: Indexed<'a, ForgetBrand<Q, R>, I, A, A>,
) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate<R: 'a + Monoid + 'static, Q: ToDynCloneFn + 'static>( &self, pab: Indexed<'a, ForgetBrand<Q, R>, I, A, A>, ) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall PointerBrand I S A F R Q. (Monoid R, ToDynCloneFn Q, IndexedFoldFunc F, ToDynCloneFn PointerBrand) => (&IndexedFoldPrime PointerBrand I S A F, Indexed (Forget Q R) I A A) -> Forget Q R S S
§Type Parameters
R: The monoid type.Q: The reference-counted pointer type.
§Parameters
&self: The indexed fold instance.pab: The indexed profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::{
IndexedFoldOptic,
ToDynCloneFn,
monoid::Monoid,
semigroup::Semigroup,
},
types::optics::*,
};
#[derive(Clone)]
struct MyFold;
impl<'a> IndexedFoldFunc<'a, usize, Vec<i32>, i32> for MyFold {
fn apply<R: 'a + Monoid + 'static>(
&self,
f: Box<dyn Fn(usize, i32) -> R + 'a>,
s: Vec<i32>,
) -> R {
s.into_iter()
.enumerate()
.fold(R::empty(), |acc, (i, x)| Semigroup::append(acc, f(i, x)))
}
}
let l: IndexedFoldPrime<RcBrand, usize, Vec<i32>, i32, MyFold> = IndexedFoldPrime::new(MyFold);
let f = Forget::<RcBrand, String, (usize, i32), i32>::new(|(i, x)| format!("[{}]={}", i, x));
let pab = Indexed::new(f);
let result = IndexedFoldOptic::evaluate::<String, RcBrand>(&l, pab);
assert_eq!(result.run(vec![10, 20]), "[0]=10[1]=20");Source§impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + Monoid + Clone + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a, F> IndexedOpticAdapter<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
Q2: The result type brand.
R: The monoid type.
PointerBrand: The original profunctor type.
I: The index type.
S: The structure type.
A: The focus type.
F: The fold function type.
impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + Monoid + Clone + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a, F> IndexedOpticAdapter<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.Q2: The result type brand.R: The monoid type.PointerBrand: The original profunctor type.I: The index type.S: The structure type.A: The focus type.F: The fold function type.
Source§fn evaluate_indexed(
&self,
pab: Indexed<'a, ForgetBrand<Q2, R>, I, A, A>,
) -> Forget<'a, Q2, R, S, S>
fn evaluate_indexed( &self, pab: Indexed<'a, ForgetBrand<Q2, R>, I, A, A>, ) -> Forget<'a, Q2, R, S, S>
§Type Signature
forall Q2 R PointerBrand I S A F. (ToDynCloneFn Q2, Monoid R, ToDynCloneFn PointerBrand, IndexedFoldFunc F) => (&IndexedFoldPrime Q2 R PointerBrand I S A F, Indexed (Forget Q2 R) I A A) -> Forget Q2 R S S
§Parameters
&self: The indexed fold instance.pab: The indexed profunctor value.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
RcBrand,
VecBrand,
optics::*,
},
functions::*,
types::optics::{
Folded,
*,
},
};
let l = IndexedFoldPrime::<RcBrand, usize, Vec<i32>, i32, Folded<VecBrand>>::folded();
let _unindexed = optics_un_index::<ForgetBrand<RcBrand, String>, _, _, _, _, _>(&l);
assert_eq!(
optics_indexed_fold_map::<RcBrand, _, _, _, String>(&l, |_, x| x.to_string(), vec![1, 2]),
"12"
);Source§impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + Monoid + Clone + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a, F> IndexedOpticAdapterDiscardsFocus<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
Q2: The result type brand.
R: The monoid type.
PointerBrand: The original profunctor type.
I: The index type.
S: The structure type.
A: The focus type.
F: The fold function type.
impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + Monoid + Clone + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a, F> IndexedOpticAdapterDiscardsFocus<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: IndexedFoldFunc<'a, I, S, A> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.Q2: The result type brand.R: The monoid type.PointerBrand: The original profunctor type.I: The index type.S: The structure type.A: The focus type.F: The fold function type.
Source§fn evaluate_indexed_discards_focus(
&self,
pab: Indexed<'a, ForgetBrand<Q2, R>, I, A, A>,
) -> Forget<'a, Q2, R, S, S>
fn evaluate_indexed_discards_focus( &self, pab: Indexed<'a, ForgetBrand<Q2, R>, I, A, A>, ) -> Forget<'a, Q2, R, S, S>
§Type Signature
forall Q2 R PointerBrand I S A F. (ToDynCloneFn Q2, Monoid R, ToDynCloneFn PointerBrand, IndexedFoldFunc F) => (&IndexedFoldPrime Q2 R PointerBrand I S A F, Indexed (Forget Q2 R) I A A) -> Forget Q2 R S S
§Parameters
&self: The indexed fold instance.pab: The indexed profunctor value.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
RcBrand,
VecBrand,
optics::*,
},
functions::*,
types::optics::{
Folded,
*,
},
};
let l = IndexedFoldPrime::<RcBrand, usize, Vec<i32>, i32, Folded<VecBrand>>::folded();
let _unindexed = optics_as_index::<ForgetBrand<RcBrand, String>, _, _, _, _, _>(&l);
assert_eq!(
optics_indexed_fold_map::<RcBrand, _, _, _, String>(&l, |i, _| i.to_string(), vec![1, 2]),
"01"
);Auto Trait Implementations§
impl<'a, PointerBrand, I, S, A, F> Freeze for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: Freeze,
impl<'a, PointerBrand, I, S, A, F> RefUnwindSafe for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: RefUnwindSafe,
PointerBrand: RefUnwindSafe,
I: RefUnwindSafe,
S: RefUnwindSafe,
A: RefUnwindSafe,
impl<'a, PointerBrand, I, S, A, F> Send for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>
impl<'a, PointerBrand, I, S, A, F> Sync for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>
impl<'a, PointerBrand, I, S, A, F> Unpin for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>
impl<'a, PointerBrand, I, S, A, F> UnsafeUnpin for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: UnsafeUnpin,
impl<'a, PointerBrand, I, S, A, F> UnwindSafe for IndexedFoldPrime<'a, PointerBrand, I, S, A, F>where
F: UnwindSafe,
PointerBrand: UnwindSafe,
I: RefUnwindSafe,
S: RefUnwindSafe,
A: 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