Skip to main content

Grate

Struct Grate 

Source
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.
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>, B>) -> T + 'a, ) -> Self
where <PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,

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));
Source

pub fn zip_with(&self, f: impl Fn((A, A)) -> B + 'a, s1: S, s2: S) -> T
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 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 returning B.
  • 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.
Source§

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)

Performs copy-assignment from source. Read more
Source§

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,

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

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

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