pub struct IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
I: 'a,
S: 'a,
A: 'a,{ /* private fields */ }Expand description
A polymorphic indexed getter.
§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.
Implementations§
Source§impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
§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.
impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
§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.
Sourcepub fn new(to: impl 'a + Fn(S) -> (I, A)) -> Self
pub fn new(to: impl 'a + Fn(S) -> (I, A)) -> Self
Create a new indexed getter.
§Type Signature
forall PointerBrand I S A. ToDynCloneFn PointerBrand => (S -> (I, A)) -> IndexedGetter PointerBrand I S A
§Parameters
to: The getter function.
§Returns
A new IndexedGetter instance.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::IndexedGetter,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
assert_eq!(g.iview((42, "hi".to_string())), (0, 42));Sourcepub fn iview(&self, s: S) -> (I, A)
pub fn iview(&self, s: S) -> (I, A)
View the focus and its index.
§Type Signature
forall PointerBrand I S A. ToDynCloneFn PointerBrand => (&IndexedGetter PointerBrand I S A, S) -> (I, A)
§Parameters
&self: The indexed getter instance.s: The structure to view.
§Returns
The focus value and its index.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::IndexedGetter,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
assert_eq!(g.iview((42, "hi".to_string())), (0, 42));Trait Implementations§
Source§impl<'a, PointerBrand, I, S, A> Clone for IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
I: 'a,
S: 'a,
A: '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.
impl<'a, PointerBrand, I, S, A> Clone for IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
I: 'a,
S: 'a,
A: '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.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall PointerBrand I S A. ToDynCloneFn PointerBrand => &IndexedGetter PointerBrand I S A -> IndexedGetter PointerBrand I S A
§Returns
A new IndexedGetter instance that is a copy of the original.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::IndexedGetter,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
let cloned = g.clone();
assert_eq!(cloned.iview((42, "hi".to_string())), (0, 42));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> IndexedFoldOptic<'a, I, S, A> for IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
§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.
impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedFoldOptic<'a, I, S, A> for IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
§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.
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 R Q. (Monoid R, ToDynCloneFn Q, ToDynCloneFn PointerBrand) => (&IndexedGetter PointerBrand I S A, 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 getter instance.pab: The indexed profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
types::optics::*,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
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>(&g, pab);
assert_eq!(result.run((42, "hi".to_string())), "[0]=42");Source§impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedGetterOptic<'a, I, S, A> for IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
§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.
impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedGetterOptic<'a, I, S, A> for IndexedGetter<'a, PointerBrand, I, S, A>where
PointerBrand: ToDynCloneFn,
§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.
Source§fn evaluate<R: 'a + '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 + '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 R Q. (ToDynCloneFn Q, ToDynCloneFn PointerBrand) => (&IndexedGetter PointerBrand I S A, Indexed (Forget Q R) I A A) -> Forget Q R S S
§Type Parameters
R: The result type.Q: The reference-counted pointer type.
§Parameters
&self: The indexed getter instance.pab: The indexed profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
types::optics::*,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
let f = Forget::<RcBrand, i32, (usize, i32), i32>::new(|(i, x)| x + (i as i32));
let pab = Indexed::new(f);
let result = IndexedGetterOptic::evaluate::<i32, RcBrand>(&g, pab);
assert_eq!(result.run((42, "hi".to_string())), 42);Source§impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a> IndexedOpticAdapter<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedGetter<'a, PointerBrand, I, S, A>
§Type Parameters
'a: The lifetime of the values.
Q2: The result type brand.
R: The result type.
PointerBrand: The original pointer type.
I: The index type.
S: The structure type.
A: The focus type.
impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a> IndexedOpticAdapter<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedGetter<'a, PointerBrand, I, S, A>
§Type Parameters
'a: The lifetime of the values.Q2: The result type brand.R: The result type.PointerBrand: The original pointer type.I: The index type.S: The structure type.A: The focus 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. (ToDynCloneFn Q2, ToDynCloneFn PointerBrand) => (&IndexedGetter Q2 R PointerBrand I S A, Indexed (Forget Q2 R) I A A) -> Forget Q2 R S S
§Parameters
&self: The indexed getter instance.pab: The indexed profunctor value.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
functions::*,
types::optics::*,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
let result = optics_indexed_view::<RcBrand, _, _, _>(&g, (42, "hi".to_string()));
assert_eq!(result, (0, 42));Source§impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a> IndexedOpticAdapterDiscardsFocus<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedGetter<'a, PointerBrand, I, S, A>
§Type Parameters
'a: The lifetime of the values.
Q2: The result type brand.
R: The result type.
PointerBrand: The original pointer type.
I: The index type.
S: The structure type.
A: The focus type.
impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a> IndexedOpticAdapterDiscardsFocus<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedGetter<'a, PointerBrand, I, S, A>
§Type Parameters
'a: The lifetime of the values.Q2: The result type brand.R: The result type.PointerBrand: The original pointer type.I: The index type.S: The structure type.A: The focus 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. (ToDynCloneFn Q2, ToDynCloneFn PointerBrand) => (&IndexedGetter Q2 R PointerBrand I S A, Indexed (Forget Q2 R) I A A) -> Forget Q2 R S S
§Parameters
&self: The indexed getter instance.pab: The indexed profunctor value.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
functions::*,
types::optics::*,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (10, x));
let result = optics_indexed_fold_map::<RcBrand, _, _, _, String>(
&g,
|i, _| format!("{}", i),
(42, "hi".to_string()),
);
assert_eq!(result, "10");Auto Trait Implementations§
impl<'a, PointerBrand, I, S, A> Freeze for IndexedGetter<'a, PointerBrand, I, S, A>
impl<'a, PointerBrand, I, S, A> RefUnwindSafe for IndexedGetter<'a, PointerBrand, I, S, A>
impl<'a, PointerBrand, I, S, A> Send for IndexedGetter<'a, PointerBrand, I, S, A>
impl<'a, PointerBrand, I, S, A> Sync for IndexedGetter<'a, PointerBrand, I, S, A>
impl<'a, PointerBrand, I, S, A> Unpin for IndexedGetter<'a, PointerBrand, I, S, A>
impl<'a, PointerBrand, I, S, A> UnsafeUnpin for IndexedGetter<'a, PointerBrand, I, S, A>
impl<'a, PointerBrand, I, S, A> UnwindSafe for IndexedGetter<'a, PointerBrand, I, 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
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