pub struct Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,{
pub grate: <FnBrand<PointerBrand> as CloneFn>::Of<'a, <FnBrand<PointerBrand> as CloneFn>::Of<'a, <FnBrand<PointerBrand> as CloneFn>::Of<'a, <PointerBrand as RefCountedPointer>::Of<'a, S>, A>, B>, T>,
}Expand description
A polymorphic grate.
Matches PureScript’s Grate s t a b.
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer 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.
Fields§
§grate: <FnBrand<PointerBrand> as CloneFn>::Of<'a, <FnBrand<PointerBrand> as CloneFn>::Of<'a, <FnBrand<PointerBrand> as CloneFn>::Of<'a, <PointerBrand as RefCountedPointer>::Of<'a, S>, A>, B>, T>Grating function.
Implementations§
Source§impl<'a, PointerBrand, S, T, A, B> Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a + Clone,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer 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.
impl<'a, PointerBrand, S, T, A, B> Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a + Clone,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer 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.
Sourcepub fn new(
grate: impl Fn(<FnBrand<PointerBrand> as CloneFn>::Of<'a, <FnBrand<PointerBrand> as CloneFn>::Of<'a, <PointerBrand as RefCountedPointer>::Of<'a, S>, A>, B>) -> T + 'a,
) -> Self
pub fn new( grate: impl Fn(<FnBrand<PointerBrand> as CloneFn>::Of<'a, <FnBrand<PointerBrand> as CloneFn>::Of<'a, <PointerBrand as RefCountedPointer>::Of<'a, S>, A>, B>) -> T + 'a, ) -> Self
Creates a new Grate instance.
§Type Signature
forall PointerBrand S T A B. ToDynCloneFn PointerBrand => (Fn PointerBrand (Fn PointerBrand (PointerBrand S) A) B -> T) -> Grate PointerBrand S T A B
§Parameters
grate: The grating function.
§Returns
A new instance of the type.
§Examples
use {
fp_library::{
brands::*,
classes::*,
types::optics::Grate,
},
std::rc::Rc,
};
let grate = Grate::<'_, RcBrand, (i32, i32), (i32, i32), i32, i32>::new(|f| {
let get_x = <RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0);
let get_y = <RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1);
(f(get_x), f(get_y))
});
assert_eq!(grate.zip_with(|(a, b)| a + b, (1, 2), (3, 4)), (4, 6));Sourcepub fn zip_with(&self, f: impl Fn((A, A)) -> B + 'a, s1: S, s2: S) -> T
pub fn zip_with(&self, f: impl Fn((A, A)) -> B + 'a, s1: S, s2: S) -> T
Zip two structures together using this grate and a combining function.
Convenience method wrapping zip_with_of.
§Type Signature
forall PointerBrand S T A B. ToDynCloneFn PointerBrand => (&Grate PointerBrand S T A B, (A, A) -> B, S, S) -> T
§Parameters
&self: The grate instance.f: The combining function, taking a pair(A, A)and returningB.s1: The first structure.s2: The second structure.
§Returns
The combined structure.
§Examples
use {
fp_library::{
brands::*,
classes::*,
types::optics::Grate,
},
std::rc::Rc,
};
let grate = Grate::<'_, RcBrand, (i32, i32), (i32, i32), i32, i32>::new(|f| {
let get_x = <RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0);
let get_y = <RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1);
(f(get_x), f(get_y))
});
let result = grate.zip_with(|(a, b)| a + b, (1, 2), (10, 20));
assert_eq!(result, (11, 22));Trait Implementations§
Source§impl<'a, PointerBrand, S, T, A, B> Clone for Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer 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.
impl<'a, PointerBrand, S, T, A, B> Clone for Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer 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.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall PointerBrand S T A B. ToDynCloneFn PointerBrand => &Grate PointerBrand S T A B -> Grate PointerBrand S T A B
§Returns
A new Grate instance that is a copy of the original.
§Examples
use {
fp_library::{
brands::*,
classes::*,
types::optics::Grate,
},
std::rc::Rc,
};
let grate = Grate::<'_, RcBrand, (i32, i32), (i32, i32), i32, i32>::new(|f| {
let get_x = <RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0);
let get_y = <RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1);
(f(get_x), f(get_y))
});
let cloned = grate.clone();
assert_eq!(cloned.zip_with(|(a, b)| a + b, (1, 2), (3, 4)), (4, 6));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, T, A, B> GrateOptic<'a, FnBrand<PointerBrand>, S, T, A, B> for Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer 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.
impl<'a, PointerBrand, S, T, A, B> GrateOptic<'a, FnBrand<PointerBrand>, S, T, A, B> for Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer 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.
Source§fn evaluate<Q: Closed<FnBrand<PointerBrand>>>(
&self,
pab: <Q as Kind_266801a817966495>::Of<'a, A, B>,
) -> <Q as Kind_266801a817966495>::Of<'a, S, T>where
T: 'a,
B: 'a,
fn evaluate<Q: Closed<FnBrand<PointerBrand>>>(
&self,
pab: <Q as Kind_266801a817966495>::Of<'a, A, B>,
) -> <Q as Kind_266801a817966495>::Of<'a, S, T>where
T: 'a,
B: 'a,
§Type Signature
forall PointerBrand S T A B Q. (Closed Q, ToDynCloneFn PointerBrand) => (&Grate PointerBrand S T A B, Q A B) -> Q S T
§Type Parameters
Q: The profunctor type.
§Parameters
&self: The grate instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use {
fp_library::{
brands::*,
classes::{
optics::*,
profunctor::*,
*,
},
types::optics::Grate,
},
std::rc::Rc,
};
let grate = Grate::<'_, RcBrand, (i32, i32), (i32, i32), i32, i32>::new(|f| {
(
f(Rc::new(|s: Rc<(i32, i32)>| s.0) as Rc<dyn Fn(Rc<(i32, i32)>) -> i32>),
f(Rc::new(|s: Rc<(i32, i32)>| s.1) as Rc<dyn Fn(Rc<(i32, i32)>) -> i32>),
)
});
let f = Rc::new(|x: i32| x + 1) as Rc<dyn Fn(i32) -> i32>;
let g = GrateOptic::<RcFnBrand, _, _, _, _>::evaluate::<RcFnBrand>(&grate, f);
assert_eq!(g((10, 20)), (11, 21));Source§impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, Q, S, T, A, B> for Grate<'a, PointerBrand, S, T, A, B>where
Q: Closed<FnBrand<PointerBrand>>,
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,
§Type Parameters
'a: The lifetime of the values.
Q: The profunctor type.
PointerBrand: The reference-counted pointer 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.
impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, Q, S, T, A, B> for Grate<'a, PointerBrand, S, T, A, B>where
Q: Closed<FnBrand<PointerBrand>>,
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer 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.
Source§fn evaluate(
&self,
pab: <Q as Kind_266801a817966495>::Of<'a, A, B>,
) -> <Q as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate( &self, pab: <Q as Kind_266801a817966495>::Of<'a, A, B>, ) -> <Q as Kind_266801a817966495>::Of<'a, S, T>
Evaluates the grate with a profunctor.
§Type Signature
forall Q PointerBrand S T A B. (Closed Q, ToDynCloneFn PointerBrand) => (&Grate Q PointerBrand S T A B, Q A B) -> Q S T
§Parameters
&self: The grate instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use {
fp_library::{
brands::*,
classes::{
optics::*,
*,
},
types::optics::Grate,
},
std::rc::Rc,
};
let grate = Grate::<'_, RcBrand, (i32, i32), (i32, i32), i32, i32>::new(
|f: Rc<dyn Fn(Rc<dyn Fn(Rc<(i32, i32)>) -> i32>) -> i32>| {
let get_x = <RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0);
let get_y = <RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1);
(f(get_x), f(get_y))
},
);
let f = Rc::new(|x: i32| x + 1) as Rc<dyn Fn(i32) -> i32>;
let g = Optic::<RcFnBrand, _, _, _, _>::evaluate(&grate, f);
assert_eq!(g((10, 20)), (11, 21));Source§impl<'a, PointerBrand, S, T, A, B> SetterOptic<'a, PointerBrand, S, T, A, B> for Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,
§Type Parameters
'a: The lifetime of the values.
PointerBrand: The reference-counted pointer 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.
impl<'a, PointerBrand, S, T, A, B> SetterOptic<'a, PointerBrand, S, T, A, B> for Grate<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer 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.
Source§fn evaluate(
&self,
pab: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, A, B>,
) -> <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate( &self, pab: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, A, B>, ) -> <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, S, T>
§Type Signature
forall PointerBrand S T A B. ToDynCloneFn PointerBrand => (&Grate PointerBrand S T A B, Fn PointerBrand A B) -> Fn PointerBrand S T
§Parameters
&self: The grate instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use {
fp_library::{
brands::*,
classes::{
optics::*,
profunctor::*,
*,
},
types::optics::Grate,
},
std::rc::Rc,
};
let grate = Grate::<'_, RcBrand, (i32, i32), (i32, i32), i32, i32>::new(|f| {
(
f(Rc::new(|s: Rc<(i32, i32)>| s.0) as Rc<dyn Fn(Rc<(i32, i32)>) -> i32>),
f(Rc::new(|s: Rc<(i32, i32)>| s.1) as Rc<dyn Fn(Rc<(i32, i32)>) -> i32>),
)
});
let f = Rc::new(|x: i32| x + 1) as Rc<dyn Fn(i32) -> i32>;
let g: Rc<dyn Fn((i32, i32)) -> (i32, i32)> =
SetterOptic::<RcBrand, _, _, _, _>::evaluate(&grate, f);
assert_eq!(g((10, 20)), (11, 21));Auto Trait Implementations§
impl<'a, PointerBrand, S, T, A, B> Freeze for Grate<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, S>) -> A + 'a>) -> B + 'a>) -> T + 'a>: Freeze,
impl<'a, PointerBrand, S, T, A, B> RefUnwindSafe for Grate<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, S>) -> A + 'a>) -> B + 'a>) -> T + 'a>: RefUnwindSafe,
impl<'a, PointerBrand, S, T, A, B> Send for Grate<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, S>) -> A + 'a>) -> B + 'a>) -> T + 'a>: Send,
impl<'a, PointerBrand, S, T, A, B> Sync for Grate<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, S>) -> A + 'a>) -> B + 'a>) -> T + 'a>: Sync,
impl<'a, PointerBrand, S, T, A, B> Unpin for Grate<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, S>) -> A + 'a>) -> B + 'a>) -> T + 'a>: Unpin,
impl<'a, PointerBrand, S, T, A, B> UnsafeUnpin for Grate<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, S>) -> A + 'a>) -> B + 'a>) -> T + 'a>: UnsafeUnpin,
impl<'a, PointerBrand, S, T, A, B> UnwindSafe for Grate<'a, PointerBrand, S, T, A, B>where
<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(<PointerBrand as RefCountedPointer>::Of<'a, S>) -> A + '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