pub struct Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,{
pub over_fn: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, (S, Box<dyn Fn(A) -> B + 'a>), T>,
}Expand description
A polymorphic setter.
Matches PureScript’s Setter s t a b.
§Type Parameters
'a: The lifetime of the values.PointerBrand: The pointer brand for the function.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.
Fields§
§over_fn: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, (S, Box<dyn Fn(A) -> B + 'a>), T>Function to update the focus in a structure.
Implementations§
Source§impl<'a, PointerBrand, S, T, A, B> Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The pointer brand for the function.
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.
impl<'a, PointerBrand, S, T, A, B> Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The pointer brand for the function.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.
Sourcepub fn new(over: impl 'a + Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T) -> Self
pub fn new(over: impl 'a + Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T) -> Self
Create a new polymorphic setter.
§Type Signature
forall PointerBrand S T A B. UnsizedCoercible PointerBrand => ((S, dyn (A -> B)) -> T) -> Setter PointerBrand S T A B
§Parameters
over: The over function.
§Returns
A new instance of the type.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::Setter,
};
let s: Setter<RcBrand, (i32, String), (i32, String), i32, i32> =
Setter::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
assert_eq!(s.over((42, "hi".to_string()), |x| x + 1), (43, "hi".to_string()));Sourcepub fn over(&self, s: S, f: impl Fn(A) -> B + 'a) -> T
pub fn over(&self, s: S, f: impl Fn(A) -> B + 'a) -> T
Update the focus of the setter in a structure using a function.
§Type Signature
forall PointerBrand S T A B. UnsizedCoercible PointerBrand => (&Setter PointerBrand S T A B, S, A -> B) -> T
§Parameters
&self: The 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,
types::optics::Setter,
};
let s: Setter<RcBrand, (i32, String), (i32, String), i32, i32> =
Setter::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
assert_eq!(s.over((42, "hi".to_string()), |x| x + 1), (43, "hi".to_string()));Trait Implementations§
Source§impl<'a, PointerBrand, S, T, A, B> Clone for Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The pointer brand for the function.
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.
impl<'a, PointerBrand, S, T, A, B> Clone for Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The pointer brand for the function.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.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall PointerBrand S T A B. UnsizedCoercible PointerBrand => &Setter PointerBrand S T A B -> Setter PointerBrand S T A B
§Returns
A new Setter instance that is a copy of the original.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::Setter,
};
let s: Setter<RcBrand, (i32, String), (i32, String), i32, i32> =
Setter::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
let cloned = s.clone();
assert_eq!(cloned.over((42, "hi".to_string()), |x| x + 1), (43, "hi".to_string()));1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, FnBrand<Q>, S, T, A, B> for Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.
Q: The pointer brand for the setter.
PointerBrand: The source type of the structure.
S: The target type of the structure.
T: The source type of the focus.
A: The target type of the focus.
B: The pointer brand for the function profunctor.
impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, FnBrand<Q>, S, T, A, B> for Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The pointer brand for the setter.PointerBrand: The source type of the structure.S: The target type of the structure.T: The source type of the focus.A: The target type of the focus.B: The pointer brand for the function profunctor.
Source§fn evaluate(
&self,
pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, B>,
) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate( &self, pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, B>, ) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall Q PointerBrand S T A B. (UnsizedCoercible PointerBrand, UnsizedCoercible Q) => (&Setter Q PointerBrand S T A B, Fn Q A B) -> Fn Q S T
§Parameters
&self: The setter instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
functions::*,
types::optics::*,
};
let s: Setter<RcBrand, (i32, String), (i32, String), i32, i32> =
Setter::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x + 1);
let modifier = Optic::<RcFnBrand, _, _, _, _>::evaluate(&s, f);
assert_eq!(modifier((42, "hi".to_string())), (43, "hi".to_string()));Source§impl<'a, Q, PointerBrand, S, T, A, B> SetterOptic<'a, Q, S, T, A, B> for Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.
Q: The pointer brand for the setter.
PointerBrand: The source type of the structure.
S: The target type of the structure.
T: The source type of the focus.
A: The target type of the focus.
B: The pointer brand for the function profunctor.
impl<'a, Q, PointerBrand, S, T, A, B> SetterOptic<'a, Q, S, T, A, B> for Setter<'a, PointerBrand, S, T, A, B>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The pointer brand for the setter.PointerBrand: The source type of the structure.S: The target type of the structure.T: The source type of the focus.A: The target type of the focus.B: The pointer brand for the function profunctor.
Source§fn evaluate(
&self,
pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, B>,
) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate( &self, pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, B>, ) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall Q PointerBrand S T A B. (UnsizedCoercible PointerBrand, UnsizedCoercible Q) => (&Setter Q PointerBrand S T A B, Fn Q A B) -> Fn Q S T
§Parameters
&self: The setter instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use {
fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
functions::*,
types::optics::*,
},
std::rc::Rc,
};
let s: Setter<RcBrand, (i32, String), (i32, String), i32, i32> =
Setter::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x + 1);
let modifier: Rc<dyn Fn((i32, String)) -> (i32, String)> =
SetterOptic::<RcBrand, _, _, _, _>::evaluate(&s, f);
assert_eq!(modifier((42, "hi".to_string())), (43, "hi".to_string()));Auto Trait Implementations§
impl<'a, PointerBrand, S, T, A, B> Freeze for Setter<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T + 'a>: Freeze,
impl<'a, PointerBrand, S, T, A, B> RefUnwindSafe for Setter<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T + 'a>: RefUnwindSafe,
impl<'a, PointerBrand, S, T, A, B> Send for Setter<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T + 'a>: Send,
impl<'a, PointerBrand, S, T, A, B> Sync for Setter<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T + 'a>: Sync,
impl<'a, PointerBrand, S, T, A, B> Unpin for Setter<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T + 'a>: Unpin,
impl<'a, PointerBrand, S, T, A, B> UnsafeUnpin for Setter<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T + 'a>: UnsafeUnpin,
impl<'a, PointerBrand, S, T, A, B> UnwindSafe for Setter<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T + 'a>: UnwindSafe,
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