pub struct GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,{
pub view_fn: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, S, A>,
/* private fields */
}Expand description
A concrete getter type where types do not change.
Matches PureScript’s Getter' s a.
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
Fields§
§view_fn: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, S, A>Function to view the focus of the getter in a structure.
Implementations§
Source§impl<'a, PointerBrand, S, A> GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
S: The type of the structure.
A: The type of the focus.
impl<'a, PointerBrand, S, A> GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
Sourcepub fn new(view: impl 'a + Fn(S) -> A) -> Self
pub fn new(view: impl 'a + Fn(S) -> A) -> Self
Create a new monomorphic getter from a view function.
§Type Signature
forall PointerBrand S A. UnsizedCoercible PointerBrand => (S -> A) -> GetterPrime PointerBrand S A
§Parameters
view: The view function.
§Returns
A new instance of the type.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::GetterPrime,
};
let g: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
assert_eq!(g.view((42, "hi".to_string())), 42);Sourcepub fn view(&self, s: S) -> A
pub fn view(&self, s: S) -> A
View the focus of the getter in a structure.
§Type Signature
forall PointerBrand S A. UnsizedCoercible PointerBrand => (&GetterPrime PointerBrand S A, S) -> A
§Parameters
&self: The getter instance.s: The structure to view.
§Returns
The focus value.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::GetterPrime,
};
let g: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
assert_eq!(g.view((42, "hi".to_string())), 42);Trait Implementations§
Source§impl<'a, PointerBrand, S, A> Clone for GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
S: The type of the structure.
A: The type of the focus.
impl<'a, PointerBrand, S, A> Clone for GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.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 => &GetterPrime PointerBrand S A -> GetterPrime PointerBrand S A
§Returns
A new GetterPrime instance that is a copy of the original.
§Examples
use fp_library::{
brands::RcBrand,
types::optics::GetterPrime,
};
let g: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
let cloned = g.clone();
assert_eq!(cloned.view((42, "hi".to_string())), 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, S: 'a, A: 'a> FoldOptic<'a, S, A> for GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
S: The type of the structure.
A: The type of the focus.
impl<'a, PointerBrand, S: 'a, A: 'a> FoldOptic<'a, S, A> for GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
Source§fn evaluate<R: 'a + Monoid + 'static, Q: UnsizedCoercible + 'static>(
&self,
pab: <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, A, A>,
) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate<R: 'a + Monoid + 'static, Q: UnsizedCoercible + 'static>( &self, pab: <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall PointerBrand S A R Q. (Monoid R, UnsizedCoercible Q, UnsizedCoercible PointerBrand) => (&GetterPrime PointerBrand S A, Forget Q R A A) -> Forget Q R S S
§Type Parameters
R: The monoid type.Q: The reference-counted pointer type for the Forget brand.
§Parameters
&self: The getter instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
functions::*,
types::optics::*,
};
let g: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
let f = Forget::<RcBrand, String, i32, i32>::new(|x: i32| x.to_string());
let folded: Forget<RcBrand, String, (i32, String), (i32, String)> = FoldOptic::evaluate(&g, f);
assert_eq!(folded.run((42, "hi".to_string())), "42".to_string());Source§impl<'a, PointerBrand, S: 'a, A: 'a> GetterOptic<'a, S, A> for GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type.
S: The type of the structure.
A: The type of the focus.
impl<'a, PointerBrand, S: 'a, A: 'a> GetterOptic<'a, S, A> for GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
Source§fn evaluate<R: 'a + 'static, Q: UnsizedCoercible + 'static>(
&self,
pab: <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, A, A>,
) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate<R: 'a + 'static, Q: UnsizedCoercible + 'static>( &self, pab: <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall PointerBrand S A R Q. (UnsizedCoercible Q, UnsizedCoercible PointerBrand) => (&GetterPrime PointerBrand S A, Forget Q R A A) -> Forget Q R S S
§Type Parameters
R: The return type of the forget profunctor.Q: The reference-counted pointer type.
§Parameters
&self: The getter instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
functions::*,
types::optics::*,
};
let g: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
let f = Forget::<RcBrand, i32, i32, i32>::new(|x| x);
let folded = GetterOptic::evaluate(&g, f);
assert_eq!(folded.run((42, "hi".to_string())), 42);Source§impl<'a, PointerBrand, S, A, R, Q> Optic<'a, ForgetBrand<Q, R>, S, S, A, A> for GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible + 'static,
S: 'a,
A: 'a,
R: 'a + 'static,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer type for the getter.
S: The type of the structure.
A: The type of the focus.
R: The return type of the forget profunctor.
Q: The reference-counted pointer type for the forget brand.
impl<'a, PointerBrand, S, A, R, Q> Optic<'a, ForgetBrand<Q, R>, S, S, A, A> for GetterPrime<'a, PointerBrand, S, A>where
PointerBrand: UnsizedCoercible,
Q: UnsizedCoercible + 'static,
S: 'a,
A: 'a,
R: 'a + 'static,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type for the getter.S: The type of the structure.A: The type of the focus.R: The return type of the forget profunctor.Q: The reference-counted pointer type for the forget brand.
Source§fn evaluate(
&self,
pab: <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, A, A>,
) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate( &self, pab: <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <ForgetBrand<Q, R> as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall PointerBrand S A R Q. (UnsizedCoercible PointerBrand, UnsizedCoercible Q) => (&GetterPrime PointerBrand S A R Q, Forget Q R A A) -> Forget Q R S S
§Parameters
&self: The getter instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
functions::*,
types::optics::*,
};
let g: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
let f = Forget::<RcBrand, i32, i32, i32>::new(|x| x);
let folded = Optic::<ForgetBrand<RcBrand, i32>, _, _, _, _>::evaluate(&g, f);
assert_eq!(folded.run((42, "hi".to_string())), 42);Auto Trait Implementations§
impl<'a, PointerBrand, S, A> Freeze for GetterPrime<'a, PointerBrand, S, A>
impl<'a, PointerBrand, S, A> RefUnwindSafe for GetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(S) -> A + 'a>: RefUnwindSafe,
PointerBrand: RefUnwindSafe,
impl<'a, PointerBrand, S, A> Send for GetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(S) -> A + 'a>: Send,
PointerBrand: Send,
impl<'a, PointerBrand, S, A> Sync for GetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(S) -> A + 'a>: Sync,
PointerBrand: Sync,
impl<'a, PointerBrand, S, A> Unpin for GetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(S) -> A + 'a>: Unpin,
PointerBrand: Unpin,
impl<'a, PointerBrand, S, A> UnsafeUnpin for GetterPrime<'a, PointerBrand, S, A>
impl<'a, PointerBrand, S, A> UnwindSafe for GetterPrime<'a, PointerBrand, S, A>where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(S) -> A + 'a>: UnwindSafe,
PointerBrand: 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