pub struct SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,{
pub over_fn: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, (S, Box<dyn Fn(A) -> A + 'a>), S>,
}Expand description
A concrete setter type where types do not change.
Matches PureScript’s Setter' s a.
§Type Parameters
'a: The lifetime of the values.PointerBrand: The pointer brand for the function.S: The type of the structure.A: The type of the focus.
Fields§
§over_fn: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, (S, Box<dyn Fn(A) -> A + 'a>), S>Function to update the focus in a structure.
Implementations§
Source§impl<'a, PointerBrand, S, A> SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The pointer brand for the function.
S: The type of the structure.
A: The type of the focus.
impl<'a, PointerBrand, S, A> SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The pointer brand for the function.S: The type of the structure.A: The type of the focus.
Sourcepub fn new(over: impl 'a + Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S) -> Self
pub fn new(over: impl 'a + Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S) -> Self
Create a new monomorphic setter.
§Type Signature
forall PointerBrand S A. UnsizedCoercible PointerBrand => ((S, dyn (A -> A)) -> S) -> SetterPrime PointerBrand S A
§Parameters
over: The over function.
§Returns
A new instance of the type.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::SetterPrime,
};
let s: SetterPrime<RcBrand, (i32, String), i32> =
SetterPrime::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) -> A + 'a) -> S
pub fn over(&self, s: S, f: impl Fn(A) -> A + 'a) -> S
Update the focus of the setter in a structure using a function.
§Type Signature
forall PointerBrand S A. UnsizedCoercible PointerBrand => (&SetterPrime PointerBrand S A, S, A -> A) -> S
§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::SetterPrime,
};
let s: SetterPrime<RcBrand, (i32, String), i32> =
SetterPrime::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, A> Clone for SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The pointer brand for the function.
S: The type of the structure.
A: The type of the focus.
impl<'a, PointerBrand, S, A> Clone for SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The pointer brand for the function.S: The type of the structure.A: The type of the focus.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall PointerBrand S A. UnsizedCoercible PointerBrand => &SetterPrime PointerBrand S A -> SetterPrime PointerBrand S A
§Returns
A new SetterPrime instance that is a copy of the original.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::SetterPrime,
};
let s: SetterPrime<RcBrand, (i32, String), i32> =
SetterPrime::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, A> Optic<'a, FnBrand<Q>, S, S, A, A> for SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.
Q: The pointer brand for the setter.
PointerBrand: The type of the structure.
S: The type of the focus.
A: The pointer brand for the function profunctor.
impl<'a, Q, PointerBrand, S, A> Optic<'a, FnBrand<Q>, S, S, A, A> for SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The pointer brand for the setter.PointerBrand: The type of the structure.S: The type of the focus.A: The pointer brand for the function profunctor.
Source§fn evaluate(
&self,
pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, A>,
) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate( &self, pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall Q PointerBrand S A. (UnsizedCoercible PointerBrand, UnsizedCoercible Q) => (&SetterPrime Q PointerBrand S A, Fn Q A A) -> Fn Q S S
§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: SetterPrime<RcBrand, (i32, String), i32> =
SetterPrime::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, A> SetterOptic<'a, Q, S, S, A, A> for SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.
Q: The pointer brand for the setter.
PointerBrand: The type of the structure.
S: The type of the focus.
A: The pointer brand for the function profunctor.
impl<'a, Q, PointerBrand, S, A> SetterOptic<'a, Q, S, S, A, A> for SetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The pointer brand for the setter.PointerBrand: The type of the structure.S: The type of the focus.A: The pointer brand for the function profunctor.
Source§fn evaluate(
&self,
pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, A>,
) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate( &self, pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall Q PointerBrand S A. (UnsizedCoercible PointerBrand, UnsizedCoercible Q) => (&SetterPrime Q PointerBrand S A, Fn Q A A) -> Fn Q S S
§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: SetterPrime<RcBrand, (i32, String), i32> =
SetterPrime::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, A> Freeze for SetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: Freeze,
impl<'a, PointerBrand, S, A> RefUnwindSafe for SetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: RefUnwindSafe,
impl<'a, PointerBrand, S, A> Send for SetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: Send,
impl<'a, PointerBrand, S, A> Sync for SetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: Sync,
impl<'a, PointerBrand, S, A> Unpin for SetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: Unpin,
impl<'a, PointerBrand, S, A> UnsafeUnpin for SetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: UnsafeUnpin,
impl<'a, PointerBrand, S, A> UnwindSafe for SetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + '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