Skip to main content

GratePrime

Struct GratePrime 

Source
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.
Source

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
where <PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,

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.
Source

pub fn zip_with(&self, f: impl Fn((A, A)) -> A + 'a, s1: S, s2: S) -> S
where <PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,

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 returning A.
  • 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.
Source§

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)

Performs copy-assignment from source. Read more
Source§

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>

§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.
Source§

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.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pipe for T

Source§

fn pipe<B>(self, f: impl FnOnce(Self) -> B) -> B

Pipes self into a function, enabling left-to-right composition. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.