pub struct IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + 'a,{
pub traversal: F,
/* private fields */
}Expand description
A polymorphic indexed traversal.
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.F: The traversal function type.
Fields§
§traversal: FThe underlying indexed traversal function.
Implementations§
Source§impl<'a, PointerBrand, I, Brand, A, B> IndexedTraversal<'a, PointerBrand, I, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>, A, B, Traversed<Brand>>where
Brand: TraversableWithIndex<Index = I>,
A: 'a + Clone,
B: 'a + Clone,
I: 'a,
<Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The profunctor type.
I: The index type.
Brand: The brand of the traversable structure.
A: The type of the elements in the structure.
B: The type of the elements in the result.
impl<'a, PointerBrand, I, Brand, A, B> IndexedTraversal<'a, PointerBrand, I, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>, A, B, Traversed<Brand>>where
Brand: TraversableWithIndex<Index = I>,
A: 'a + Clone,
B: 'a + Clone,
I: 'a,
<Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The profunctor type.I: The index type.Brand: The brand of the traversable structure.A: The type of the elements in the structure.B: The type of the elements in the result.
Sourcepub fn traversed() -> Self
pub fn traversed() -> Self
Create an indexed traversal from a TraversableWithIndex.
§Type Signature
forall PointerBrand I Brand A B. TraversableWithIndex Brand => () -> IndexedTraversal PointerBrand I Brand A B
§Returns
A new IndexedTraversal instance.
§Examples
use fp_library::{
brands::{
RcBrand,
VecBrand,
optics::*,
},
functions::optics_indexed_fold_map,
types::optics::*,
};
let t: IndexedTraversal<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Traversed<VecBrand>> =
IndexedTraversal::traversed();
let v = vec![10, 20, 30];
let s =
optics_indexed_fold_map::<RcBrand, _, _, _, String>(&t, |i, x| format!("{}:{}", i, x), v);
assert_eq!(s, "0:101:202:30".to_string());Source§impl<'a, PointerBrand, I, S, T, A, B, F> IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
I: The index type.
S: The source type of the structure.
T: The target type of the structure after an update.
A: The source type of the focus.
B: The target type of the focus after an update.
F: The traversal function type.
impl<'a, PointerBrand, I, S, T, A, B, F> IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.F: The traversal function type.
Sourcepub fn new(traversal: F) -> Self
pub fn new(traversal: F) -> Self
Create a new indexed traversal.
§Type Signature
forall PointerBrand I S T A B F. IndexedTraversalFunc F => F -> IndexedTraversal PointerBrand I S T A B F
§Parameters
traversal: The traversal function.
§Returns
A new IndexedTraversal instance.
§Examples
use fp_library::{
brands::{
RcBrand,
RcFnBrand,
VecBrand,
optics::*,
},
classes::optics::IndexedTraversalOptic,
types::optics::*,
};
let l: IndexedTraversal<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Traversed<VecBrand>> =
IndexedTraversal::new(Traversed(std::marker::PhantomData));
let f = std::rc::Rc::new(|(i, x): (usize, i32)| x + (i as i32))
as std::rc::Rc<dyn Fn((usize, i32)) -> i32>;
let pab = Indexed::new(f);
let result: std::rc::Rc<dyn Fn(Vec<i32>) -> Vec<i32>> =
IndexedTraversalOptic::evaluate::<RcFnBrand>(&l, pab);
assert_eq!(result(vec![10, 20]), vec![10, 21]);Trait Implementations§
Source§impl<'a, PointerBrand, I, S, T, A, B, F> Clone for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
I: The index type.
S: The source type of the structure.
T: The target type of the structure after an update.
A: The source type of the focus.
B: The target type of the focus after an update.
F: The traversal function type.
impl<'a, PointerBrand, I, S, T, A, B, F> Clone for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.F: The traversal function type.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall PointerBrand I S T A B F. IndexedTraversalFunc F => &IndexedTraversal PointerBrand I S T A B F -> IndexedTraversal PointerBrand I S T A B F
§Returns
A new IndexedTraversal instance that is a copy of the original.
§Examples
use fp_library::{
brands::{
RcBrand,
RcFnBrand,
VecBrand,
optics::*,
},
classes::optics::IndexedTraversalOptic,
types::optics::*,
};
let l: IndexedTraversal<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Traversed<VecBrand>> =
IndexedTraversal::traversed();
let cloned = l.clone();
let f = std::rc::Rc::new(|(i, x): (usize, i32)| x + (i as i32))
as std::rc::Rc<dyn Fn((usize, i32)) -> i32>;
let pab = Indexed::new(f);
let result: std::rc::Rc<dyn Fn(Vec<i32>) -> Vec<i32>> =
IndexedTraversalOptic::evaluate::<RcFnBrand>(&cloned, pab);
assert_eq!(result(vec![10, 20]), vec![10, 21]);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: Clone + 'a, S: 'a, A: 'a + Clone, F> IndexedFoldOptic<'a, I, S, A> for IndexedTraversal<'a, PointerBrand, I, S, S, A, A, F>where
F: IndexedTraversalFunc<'a, I, S, S, A, A> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
I: The index type.
S: The source type of the structure.
A: The focus type.
F: The traversal function type.
impl<'a, PointerBrand, I: Clone + 'a, S: 'a, A: 'a + Clone, F> IndexedFoldOptic<'a, I, S, A> for IndexedTraversal<'a, PointerBrand, I, S, S, A, A, F>where
F: IndexedTraversalFunc<'a, I, S, S, A, A> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The source type of the structure.A: The focus type.F: The traversal function type.
Source§fn evaluate<R: 'a + Monoid + Clone + '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 + Clone + '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, IndexedTraversalFunc F) => (&IndexedTraversal 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 traversal instance.pab: The indexed profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
RcBrand,
VecBrand,
optics::*,
},
classes::optics::IndexedFoldOptic,
types::optics::*,
};
let l: IndexedTraversal<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Traversed<VecBrand>> =
IndexedTraversal::traversed();
let f = Forget::<RcBrand, String, (usize, i32), i32>::new(|(_, x)| x.to_string());
let pab = Indexed::new(f);
let result = IndexedFoldOptic::evaluate::<String, RcBrand>(&l, pab);
assert_eq!(result.run(vec![10, 20]), "1020".to_string());Source§impl<'a, P: Wander, I: Clone + 'a, S: 'a, T: 'a, A: 'a, B: 'a + Clone, PointerBrand, F> IndexedOpticAdapter<'a, P, I, S, T, A, B> for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
P: The profunctor type.
I: The index type.
S: The source type of the structure.
T: The target type of the structure after an update.
A: The source type of the focus.
B: The target type of the focus after an update.
PointerBrand: The original pointer type.
F: The traversal function type.
impl<'a, P: Wander, I: Clone + 'a, S: 'a, T: 'a, A: 'a, B: 'a + Clone, PointerBrand, F> IndexedOpticAdapter<'a, P, I, S, T, A, B> for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.P: The profunctor type.I: The index type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.PointerBrand: The original pointer type.F: The traversal function type.
Source§fn evaluate_indexed(
&self,
pab: Indexed<'a, P, I, A, B>,
) -> <P as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate_indexed( &self, pab: Indexed<'a, P, I, A, B>, ) -> <P as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall P I S T A B PointerBrand F. (Wander P, IndexedTraversalFunc F) => (&IndexedTraversal P I S T A B PointerBrand F, Indexed P I A B) -> P S T
§Parameters
&self: The indexed traversal instance.pab: The indexed profunctor value.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
FnBrand,
RcBrand,
VecBrand,
optics::*,
},
functions::*,
types::optics::*,
};
let l: IndexedTraversal<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Traversed<VecBrand>> =
IndexedTraversal::traversed();
let _unindexed = optics_un_index::<FnBrand<RcBrand>, _, _, _, _, _>(&l);
assert_eq!(optics_indexed_over::<RcBrand, _, _, _>(&l, vec![1, 2], |_i, x| x + 1), vec![2, 3]);Source§impl<'a, P: Wander, I: Clone + 'a, S: 'a, T: 'a, A: 'a, B: 'a + Clone, PointerBrand, F> IndexedOpticAdapterDiscardsFocus<'a, P, I, S, T, A, B> for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
P: The profunctor type.
I: The index type.
S: The source type of the structure.
T: The target type of the structure after an update.
A: The source type of the focus.
B: The target type of the focus after an update.
PointerBrand: The original pointer type.
F: The traversal function type.
impl<'a, P: Wander, I: Clone + 'a, S: 'a, T: 'a, A: 'a, B: 'a + Clone, PointerBrand, F> IndexedOpticAdapterDiscardsFocus<'a, P, I, S, T, A, B> for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.P: The profunctor type.I: The index type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.PointerBrand: The original pointer type.F: The traversal function type.
Source§fn evaluate_indexed_discards_focus(
&self,
pab: Indexed<'a, P, I, A, B>,
) -> <P as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate_indexed_discards_focus( &self, pab: Indexed<'a, P, I, A, B>, ) -> <P as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall P I S T A B PointerBrand F. (Wander P, IndexedTraversalFunc F) => (&IndexedTraversal P I S T A B PointerBrand F, Indexed P I A B) -> P S T
§Parameters
&self: The indexed traversal instance.pab: The indexed profunctor value.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
FnBrand,
RcBrand,
VecBrand,
optics::*,
},
functions::*,
types::optics::*,
};
let l: IndexedTraversal<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Traversed<VecBrand>> =
IndexedTraversal::traversed();
let _as_index = optics_as_index::<FnBrand<RcBrand>, _, _, _, _, _>(&l);
assert_eq!(optics_indexed_over::<RcBrand, _, _, _>(&l, vec![1, 2], |_i, x| x + 1), vec![2, 3]);Source§impl<'a, Q, I: Clone + 'a, S: 'a, T: 'a, A: 'a, B: 'a + Clone, PointerBrand, F> IndexedSetterOptic<'a, Q, I, S, T, A, B> for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>
§Type Parameters
'a: The lifetime of the values.
Q: The reference-counted pointer type for the setter brand.
I: The index type.
S: The source type of the structure.
T: The target type of the structure after an update.
A: The source type of the focus.
B: The target type of the focus after an update.
PointerBrand: The reference-counted pointer type for the lens.
F: The traversal function type.
impl<'a, Q, I: Clone + 'a, S: 'a, T: 'a, A: 'a, B: 'a + Clone, PointerBrand, F> IndexedSetterOptic<'a, Q, I, S, T, A, B> for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>
§Type Parameters
'a: The lifetime of the values.Q: The reference-counted pointer type for the setter brand.I: The index type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.PointerBrand: The reference-counted pointer type for the lens.F: The traversal function type.
Source§fn evaluate(
&self,
pab: Indexed<'a, FnBrand<Q>, I, A, B>,
) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate( &self, pab: Indexed<'a, FnBrand<Q>, I, A, B>, ) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall Q I S T A B PointerBrand F. (IndexedTraversalFunc F, ToDynCloneFn Q) => (&IndexedTraversal Q I S T A B PointerBrand F, Indexed (Fn Q) I A B) -> Fn Q S T
§Parameters
&self: The indexed traversal instance.pab: The indexed profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
RcBrand,
RcFnBrand,
VecBrand,
optics::*,
},
classes::optics::IndexedSetterOptic,
types::optics::*,
};
let l: IndexedTraversal<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Traversed<VecBrand>> =
IndexedTraversal::traversed();
let f = std::rc::Rc::new(|(i, x): (usize, i32)| x + (i as i32))
as std::rc::Rc<dyn Fn((usize, i32)) -> i32>;
let pab = Indexed::<RcFnBrand, _, _, _>::new(f);
let result: std::rc::Rc<dyn Fn(Vec<i32>) -> Vec<i32>> = IndexedSetterOptic::evaluate(&l, pab);
assert_eq!(result(vec![10, 20]), vec![10, 21]);Source§impl<'a, PointerBrand, I: Clone + 'a, S: 'a, T: 'a, A: 'a, B: 'a + Clone, F> IndexedTraversalOptic<'a, I, S, T, A, B> for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
I: The index type.
S: The source type of the structure.
T: The target type of the structure after an update.
A: The source type of the focus.
B: The target type of the focus after an update.
F: The traversal function type.
impl<'a, PointerBrand, I: Clone + 'a, S: 'a, T: 'a, A: 'a, B: 'a + Clone, F> IndexedTraversalOptic<'a, I, S, T, A, B> for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedTraversalFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.F: The traversal function type.
Source§fn evaluate<Q: Wander>(
&self,
pab: Indexed<'a, Q, I, A, B>,
) -> <Q as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate<Q: Wander>( &self, pab: Indexed<'a, Q, I, A, B>, ) -> <Q as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall PointerBrand I S T A B F Q. (Wander Q, IndexedTraversalFunc F) => (&IndexedTraversal PointerBrand I S T A B F, Indexed Q I A B) -> Q S T
§Type Parameters
Q: The profunctor type.
§Parameters
&self: The indexed traversal instance.pab: The indexed profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
RcBrand,
RcFnBrand,
VecBrand,
optics::*,
},
classes::optics::IndexedTraversalOptic,
types::optics::*,
};
let l: IndexedTraversal<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Traversed<VecBrand>> =
IndexedTraversal::traversed();
let f = std::rc::Rc::new(|(i, x): (usize, i32)| x + (i as i32))
as std::rc::Rc<dyn Fn((usize, i32)) -> i32>;
let pab = Indexed::new(f);
let result: std::rc::Rc<dyn Fn(Vec<i32>) -> Vec<i32>> =
IndexedTraversalOptic::evaluate::<RcFnBrand>(&l, pab);
assert_eq!(result(vec![10, 20]), vec![10, 21]);Auto Trait Implementations§
impl<'a, PointerBrand, I, S, T, A, B, F> Freeze for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: Freeze,
impl<'a, PointerBrand, I, S, T, A, B, F> RefUnwindSafe for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: RefUnwindSafe,
PointerBrand: RefUnwindSafe,
I: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<'a, PointerBrand, I, S, T, A, B, F> Send for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>
impl<'a, PointerBrand, I, S, T, A, B, F> Sync for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>
impl<'a, PointerBrand, I, S, T, A, B, F> Unpin for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>
impl<'a, PointerBrand, I, S, T, A, B, F> UnsafeUnpin for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: UnsafeUnpin,
impl<'a, PointerBrand, I, S, T, A, B, F> UnwindSafe for IndexedTraversal<'a, PointerBrand, I, S, T, A, B, F>where
F: UnwindSafe,
PointerBrand: UnwindSafe,
I: RefUnwindSafe,
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