pub struct IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'a, I, S, T, A, B> + 'a,{
pub setter_fn: F,
/* private fields */
}Expand description
A polymorphic indexed setter.
§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 setter function type.
Fields§
§setter_fn: FThe setter function.
Implementations§
Source§impl<'a, PointerBrand, I, S, T, A, B, F> IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'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 setter function type.
impl<'a, PointerBrand, I, S, T, A, B, F> IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'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 setter function type.
Sourcepub fn new(setter_fn: F) -> Self
pub fn new(setter_fn: F) -> Self
Create a new indexed setter.
§Type Signature
forall PointerBrand I S T A B F. IndexedSetterFunc F => F -> IndexedSetter PointerBrand I S T A B F
§Parameters
setter_fn: The setter function.
§Returns
A new IndexedSetter instance.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
types::optics::*,
};
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
fn apply(
&self,
f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
s: Vec<i32>,
) -> Vec<i32> {
s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
}
}
let l: IndexedSetter<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, MySetter> =
IndexedSetter::new(MySetter);
assert_eq!(l.over(vec![10, 20], |i, x| x + (i as i32)), vec![10, 21]);Sourcepub fn over(&self, s: S, f: impl Fn(I, A) -> B + 'a) -> T
pub fn over(&self, s: S, f: impl Fn(I, A) -> B + 'a) -> T
Update the focus using an indexed function.
§Type Signature
forall PointerBrand I S T A B F. IndexedSetterFunc F => (&IndexedSetter PointerBrand I S T A B F, S, (I, A) -> B) -> T
§Parameters
&self: The indexed setter instance.s: The structure to update.f: The function to apply to the focus.
§Returns
The updated structure.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
types::optics::*,
};
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
fn apply(
&self,
f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
s: Vec<i32>,
) -> Vec<i32> {
s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
}
}
let l: IndexedSetter<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, MySetter> =
IndexedSetter::new(MySetter);
assert_eq!(l.over(vec![10, 20], |i, x| x + (i as i32)), vec![10, 21]);Sourcepub fn set(&self, s: S, b: B) -> Twhere
B: Clone + 'a,
pub fn set(&self, s: S, b: B) -> Twhere
B: Clone + 'a,
Set the focus.
§Type Signature
forall PointerBrand I S T A B F. IndexedSetterFunc F => (&IndexedSetter PointerBrand I S T A B F, S, B) -> T
§Parameters
&self: The indexed setter instance.s: The structure to update.b: The new focus value.
§Returns
The updated structure.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
types::optics::*,
};
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
fn apply(
&self,
f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
s: Vec<i32>,
) -> Vec<i32> {
s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
}
}
let l: IndexedSetter<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, MySetter> =
IndexedSetter::new(MySetter);
assert_eq!(l.set(vec![10, 20], 42), vec![42, 42]);Source§impl<'a, PointerBrand, I, Brand, A, B> IndexedSetter<'a, PointerBrand, I, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>, A, B, Mapped<Brand>>where
Brand: FunctorWithIndex<I>,
A: 'a,
B: 'a,
I: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
I: The index type.
Brand: The brand of the functor.
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> IndexedSetter<'a, PointerBrand, I, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>, A, B, Mapped<Brand>>where
Brand: FunctorWithIndex<I>,
A: 'a,
B: 'a,
I: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.I: The index type.Brand: The brand of the functor.A: The type of the elements in the structure.B: The type of the elements in the result.
Sourcepub fn mapped() -> Self
pub fn mapped() -> Self
Create an indexed setter from a FunctorWithIndex.
§Type Signature
forall PointerBrand I Brand A B. FunctorWithIndex Brand => () -> IndexedSetter PointerBrand I Brand A B
§Returns
A new IndexedSetter instance.
§Examples
use fp_library::{
brands::{
RcBrand,
VecBrand,
optics::*,
},
functions::optics_indexed_set,
types::optics::{
IndexedSetter,
Mapped,
},
};
let l: IndexedSetter<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Mapped<VecBrand>> =
IndexedSetter::mapped();
let v = vec![10, 20];
let s = optics_indexed_set::<RcBrand, _, _, _>(&l, v, 99);
assert_eq!(s, vec![99, 99]);Trait Implementations§
Source§impl<'a, PointerBrand, I, S, T, A, B, F> Clone for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'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 setter function type.
impl<'a, PointerBrand, I, S, T, A, B, F> Clone for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'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 setter function type.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall PointerBrand I S T A B F. IndexedSetterFunc F => &IndexedSetter PointerBrand I S T A B F -> IndexedSetter PointerBrand I S T A B F
§Returns
A new IndexedSetter instance that is a copy of the original.
§Examples
use fp_library::{
brands::{
RcBrand,
optics::*,
},
types::optics::*,
};
#[derive(Clone)]
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
fn apply(
&self,
f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
s: Vec<i32>,
) -> Vec<i32> {
s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
}
}
let l: IndexedSetter<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, MySetter> =
IndexedSetter::new(MySetter);
let cloned = l.clone();
assert_eq!(cloned.over(vec![10, 20], |i, x| x + (i as i32)), 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, Q2: UnsizedCoercible + 'static, PointerBrand, I: 'a, S: 'a, T: 'a, A: 'a, B: 'a, F> IndexedOpticAdapter<'a, FnBrand<Q2>, I, S, T, A, B> for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
Q2: The pointer brand for the adapter.
PointerBrand: The original pointer type.
I: The index type.
S: The source structure type.
T: The target structure type.
A: The source focus type.
B: The target focus type.
F: The setter function type.
impl<'a, Q2: UnsizedCoercible + 'static, PointerBrand, I: 'a, S: 'a, T: 'a, A: 'a, B: 'a, F> IndexedOpticAdapter<'a, FnBrand<Q2>, I, S, T, A, B> for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.Q2: The pointer brand for the adapter.PointerBrand: The original pointer type.I: The index type.S: The source structure type.T: The target structure type.A: The source focus type.B: The target focus type.F: The setter function type.
Source§fn evaluate_indexed(
&self,
pab: Indexed<'a, FnBrand<Q2>, I, A, B>,
) -> <FnBrand<Q2> as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate_indexed( &self, pab: Indexed<'a, FnBrand<Q2>, I, A, B>, ) -> <FnBrand<Q2> as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall Q2 PointerBrand I S T A B F. (UnsizedCoercible Q2, IndexedSetterFunc F) => (&IndexedSetter Q2 PointerBrand I S T A B F, Indexed (Fn Q2) I A B) -> Fn Q2 S T
§Parameters
&self: The indexed setter instance.pab: The indexed profunctor value.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
FnBrand,
RcBrand,
VecBrand,
optics::*,
},
functions::*,
types::optics::{
Mapped,
*,
},
};
let l =
IndexedSetter::<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Mapped<VecBrand>>::mapped();
let _unindexed = optics_un_index::<FnBrand<RcBrand>, _, _, _, _, _>(&l);
// optics_un_index creates a non-indexed optic; the original indexed setter still works:
assert_eq!(optics_indexed_over::<RcBrand, _, _, _>(&l, vec![1, 2], |_i, x| x + 1), vec![2, 3]);Source§impl<'a, Q2: UnsizedCoercible + 'static, PointerBrand, I: 'a, S: 'a, T: 'a, A: 'a, B: 'a, F> IndexedOpticAdapterDiscardsFocus<'a, FnBrand<Q2>, I, S, T, A, B> for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.
Q2: The pointer brand for the adapter.
PointerBrand: The original pointer type.
I: The index type.
S: The source structure type.
T: The target structure type.
A: The source focus type.
B: The target focus type.
F: The setter function type.
impl<'a, Q2: UnsizedCoercible + 'static, PointerBrand, I: 'a, S: 'a, T: 'a, A: 'a, B: 'a, F> IndexedOpticAdapterDiscardsFocus<'a, FnBrand<Q2>, I, S, T, A, B> for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: IndexedSetterFunc<'a, I, S, T, A, B> + Clone + 'a,
§Type Parameters
'a: The lifetime of the values.Q2: The pointer brand for the adapter.PointerBrand: The original pointer type.I: The index type.S: The source structure type.T: The target structure type.A: The source focus type.B: The target focus type.F: The setter function type.
Source§fn evaluate_indexed_discards_focus(
&self,
pab: Indexed<'a, FnBrand<Q2>, I, A, B>,
) -> <FnBrand<Q2> as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate_indexed_discards_focus( &self, pab: Indexed<'a, FnBrand<Q2>, I, A, B>, ) -> <FnBrand<Q2> as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall Q2 PointerBrand I S T A B F. (UnsizedCoercible Q2, IndexedSetterFunc F) => (&IndexedSetter Q2 PointerBrand I S T A B F, Indexed (Fn Q2) I A B) -> Fn Q2 S T
§Parameters
&self: The indexed setter instance.pab: The indexed profunctor value.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{FnBrand, RcBrand, VecBrand},
brands::optics::*,
types::optics::{*, Mapped},
functions::*,
};
let l = IndexedSetter::<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, Mapped<VecBrand>>::mapped();
let _unindexed = optics_as_index::<FnBrand<RcBrand>, _, _, _, _, _>(&l);
// optics_as_index creates a non-indexed optic with the index as focus; the original indexed setter still works:
assert_eq!(optics_indexed_over::<RcBrand, _, _, _>(&l, vec![1, 2], |_i, x| x + 1), vec![2, 3]);Source§impl<'a, Q, I: 'a, S: 'a, T: 'a, A: 'a, B: 'a, PointerBrand, F> IndexedSetterOptic<'a, Q, I, S, T, A, B> for IndexedSetter<'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 setter function type.
impl<'a, Q, I: 'a, S: 'a, T: 'a, A: 'a, B: 'a, PointerBrand, F> IndexedSetterOptic<'a, Q, I, S, T, A, B> for IndexedSetter<'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 setter 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. (IndexedSetterFunc F, UnsizedCoercible Q) => (&IndexedSetter Q I S T A B PointerBrand F, Indexed (Fn Q) I A B) -> Fn Q S T
§Parameters
&self: The indexed setter instance.pab: The indexed profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
types::optics::*,
};
#[derive(Clone)]
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
fn apply(
&self,
f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
s: Vec<i32>,
) -> Vec<i32> {
s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
}
}
let l: IndexedSetter<RcBrand, usize, Vec<i32>, Vec<i32>, i32, i32, MySetter> =
IndexedSetter::new(MySetter);
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]);Auto Trait Implementations§
impl<'a, PointerBrand, I, S, T, A, B, F> Freeze for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: Freeze,
impl<'a, PointerBrand, I, S, T, A, B, F> RefUnwindSafe for IndexedSetter<'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 IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>
impl<'a, PointerBrand, I, S, T, A, B, F> Sync for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>
impl<'a, PointerBrand, I, S, T, A, B, F> Unpin for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>
impl<'a, PointerBrand, I, S, T, A, B, F> UnsafeUnpin for IndexedSetter<'a, PointerBrand, I, S, T, A, B, F>where
F: UnsafeUnpin,
impl<'a, PointerBrand, I, S, T, A, B, F> UnwindSafe for IndexedSetter<'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