pub struct GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,{ /* private fields */ }Expand description
A monomorphic grate.
Matches PureScript’s Grate' 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.
Implementations§
Source§impl<'a, PointerBrand, S, A> GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
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> GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
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(
grate: impl Fn(<FnBrand<PointerBrand> as CloneFn>::Of<'a, <FnBrand<PointerBrand> as CloneFn>::Of<'a, <PointerBrand as RefCountedPointer>::Of<'a, S>, A>, A>) -> S + '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>, A>) -> S + 'a, ) -> Self
Creates a new GratePrime instance.
§Type Signature
forall PointerBrand S A. ToDynCloneFn PointerBrand => (Fn PointerBrand (Fn PointerBrand (PointerBrand S) A) A -> S) -> GratePrime PointerBrand S A
§Parameters
grate: The grating function.
§Returns
A new instance of the type.
§Examples
use {
fp_library::{
brands::*,
classes::*,
types::optics::GratePrime,
},
std::rc::Rc,
};
let grate = GratePrime::<'_, RcBrand, (i32, i32), i32>::new(
|f: Rc<dyn Fn(Rc<dyn Fn(Rc<(i32, i32)>) -> i32>) -> i32>| {
(
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0)),
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1)),
)
},
);
assert_eq!(grate.zip_with(|(a, b)| a + b, (1, 2), (3, 4)), (4, 6));Source§impl<'a, PointerBrand, S, A> GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a + Clone,
§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> GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a + Clone,
§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 zip_with(&self, f: impl Fn((A, A)) -> A + 'a, s1: S, s2: S) -> S
pub fn zip_with(&self, f: impl Fn((A, A)) -> A + 'a, s1: S, s2: S) -> S
Zip two structures together using this grate and a combining function.
Convenience method wrapping zip_with_of.
§Type Signature
forall PointerBrand S A. ToDynCloneFn PointerBrand => (&GratePrime PointerBrand S A, (A, A) -> A, S, S) -> S
§Parameters
&self: The grate instance.f: The combining function, taking a pair(A, A)and returningA.s1: The first structure.s2: The second structure.
§Returns
The combined structure.
§Examples
use {
fp_library::{
brands::*,
classes::*,
types::optics::GratePrime,
},
std::rc::Rc,
};
let grate = GratePrime::<'_, RcBrand, (i32, i32), i32>::new(
|f: Rc<dyn Fn(Rc<dyn Fn(Rc<(i32, i32)>) -> i32>) -> i32>| {
(
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0)),
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1)),
)
},
);
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, A> Clone for GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
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 GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
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. ToDynCloneFn PointerBrand => &GratePrime PointerBrand S A -> GratePrime PointerBrand S A
§Returns
The cloned grate instance.
§Examples
use {
fp_library::{
brands::*,
classes::*,
types::optics::GratePrime,
},
std::rc::Rc,
};
let grate = GratePrime::<'_, RcBrand, (i32, i32), i32>::new(
|f: Rc<dyn Fn(Rc<dyn Fn(Rc<(i32, i32)>) -> i32>) -> i32>| {
(
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0)),
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1)),
)
},
);
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, A> GrateOptic<'a, FnBrand<PointerBrand>, S, S, A, A> for GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: '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 type of the structure.
A: The type of the focus.
impl<'a, PointerBrand, S, A> GrateOptic<'a, FnBrand<PointerBrand>, S, S, A, A> for GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: '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 type of the structure.A: The type of the focus.
Source§fn evaluate<Q: Closed<FnBrand<PointerBrand>>>(
&self,
pab: <Q as Kind_266801a817966495>::Of<'a, A, A>,
) -> <Q as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate<Q: Closed<FnBrand<PointerBrand>>>( &self, pab: <Q as Kind_266801a817966495>::Of<'a, A, A>, ) -> <Q as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall PointerBrand S A Q. (Closed Q, ToDynCloneFn PointerBrand) => (&GratePrime PointerBrand S A, Q A A) -> Q S S
§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::*,
*,
},
types::optics::GratePrime,
},
std::rc::Rc,
};
let grate = GratePrime::<'_, RcBrand, (i32, i32), i32>::new(
|f: Rc<dyn Fn(Rc<dyn Fn(Rc<(i32, i32)>) -> i32>) -> i32>| {
(
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0)),
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1)),
)
},
);
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, A> Optic<'a, Q, S, S, A, A> for GratePrime<'a, PointerBrand, S, A>where
Q: Closed<FnBrand<PointerBrand>>,
PointerBrand: ToDynCloneFn,
S: 'a,
A: '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 type of the structure.
A: The type of the focus.
impl<'a, Q, PointerBrand, S, A> Optic<'a, Q, S, S, A, A> for GratePrime<'a, PointerBrand, S, A>where
Q: Closed<FnBrand<PointerBrand>>,
PointerBrand: ToDynCloneFn,
S: 'a,
A: '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 type of the structure.A: The type of the focus.
Source§fn evaluate(
&self,
pab: <Q as Kind_266801a817966495>::Of<'a, A, A>,
) -> <Q as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate( &self, pab: <Q as Kind_266801a817966495>::Of<'a, A, A>, ) -> <Q as Kind_266801a817966495>::Of<'a, S, S>
Evaluates the grate with a profunctor.
§Type Signature
forall Q PointerBrand S A. (Closed Q, ToDynCloneFn PointerBrand) => (&GratePrime Q PointerBrand S A, Q A A) -> Q S S
§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::GratePrime,
},
std::rc::Rc,
};
let grate = GratePrime::<'_, RcBrand, (i32, i32), i32>::new(
|f: Rc<dyn Fn(Rc<dyn Fn(Rc<(i32, i32)>) -> i32>) -> i32>| {
(
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.0)),
f(<RcFnBrand as LiftFn>::new(|s: Rc<(i32, i32)>| s.1)),
)
},
);
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, A> SetterOptic<'a, PointerBrand, S, S, A, A> for GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: '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 type of the structure.
A: The type of the focus.
impl<'a, PointerBrand, S, A> SetterOptic<'a, PointerBrand, S, S, A, A> for GratePrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: '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 type of the structure.A: The type of the focus.
Source§fn evaluate(
&self,
pab: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, A, A>,
) -> <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, S, S>
fn evaluate( &self, pab: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, S, S>
§Type Signature
forall PointerBrand S A. ToDynCloneFn PointerBrand => (&GratePrime PointerBrand S A, Fn PointerBrand A A) -> Fn PointerBrand S S
§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::GratePrime,
},
std::rc::Rc,
};
let grate = GratePrime::<'_, RcBrand, (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, A> Freeze for GratePrime<'a, PointerBrand, S, A>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>) -> A + 'a>) -> S + 'a>: Freeze,
impl<'a, PointerBrand, S, A> RefUnwindSafe for GratePrime<'a, PointerBrand, S, A>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>) -> A + 'a>) -> S + 'a>: RefUnwindSafe,
impl<'a, PointerBrand, S, A> Send for GratePrime<'a, PointerBrand, S, A>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>) -> A + 'a>) -> S + 'a>: Send,
impl<'a, PointerBrand, S, A> Sync for GratePrime<'a, PointerBrand, S, A>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>) -> A + 'a>) -> S + 'a>: Sync,
impl<'a, PointerBrand, S, A> Unpin for GratePrime<'a, PointerBrand, S, A>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>) -> A + 'a>) -> S + 'a>: Unpin,
impl<'a, PointerBrand, S, A> UnsafeUnpin for GratePrime<'a, PointerBrand, S, A>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>) -> A + 'a>) -> S + 'a>: UnsafeUnpin,
impl<'a, PointerBrand, S, A> UnwindSafe for GratePrime<'a, PointerBrand, S, A>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>) -> 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