Skip to main content

SetterPrime

Struct SetterPrime 

Source
pub struct SetterPrime<'a, PointerBrand, S, A>
where PointerBrand: UnsizedCoercible, S: 'a, A: 'a,
{ pub over_fn: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, (S, Box<dyn Fn(A) -> A + 'a>), S>, }
Expand description

A concrete setter type where types do not change.

Matches PureScript’s Setter' s a.

§Type Parameters

  • 'a: The lifetime of the values.
  • PointerBrand: The pointer brand for the function.
  • S: The type of the structure.
  • A: The type of the focus.

Fields§

§over_fn: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, (S, Box<dyn Fn(A) -> A + 'a>), S>

Function to update the focus in a structure.

Implementations§

Source§

impl<'a, PointerBrand, S, A> SetterPrime<'a, PointerBrand, S, A>
where PointerBrand: UnsizedCoercible, S: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The pointer brand for the function.
  • S: The type of the structure.
  • A: The type of the focus.
Source

pub fn new(over: impl 'a + Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S) -> Self

Create a new monomorphic setter.

§Type Signature

forall PointerBrand S A. UnsizedCoercible PointerBrand => ((S, dyn (A -> A)) -> S) -> SetterPrime PointerBrand S A

§Parameters
  • over: The over function.
§Returns

A new instance of the type.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::SetterPrime,
};

let s: SetterPrime<RcBrand, (i32, String), i32> =
	SetterPrime::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
assert_eq!(s.over((42, "hi".to_string()), |x| x + 1), (43, "hi".to_string()));
Source

pub fn over(&self, s: S, f: impl Fn(A) -> A + 'a) -> S

Update the focus of the setter in a structure using a function.

§Type Signature

forall PointerBrand S A. UnsizedCoercible PointerBrand => (&SetterPrime PointerBrand S A, S, A -> A) -> S

§Parameters
  • &self: The setter instance.
  • s: The structure to update.
  • f: The function to apply to the focus.
§Returns

The updated structure.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::SetterPrime,
};

let s: SetterPrime<RcBrand, (i32, String), i32> =
	SetterPrime::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
assert_eq!(s.over((42, "hi".to_string()), |x| x + 1), (43, "hi".to_string()));

Trait Implementations§

Source§

impl<'a, PointerBrand, S, A> Clone for SetterPrime<'a, PointerBrand, S, A>
where PointerBrand: UnsizedCoercible, S: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The pointer brand for the function.
  • S: The type of the structure.
  • A: The type of the focus.
Source§

fn clone(&self) -> Self

§Type Signature

forall PointerBrand S A. UnsizedCoercible PointerBrand => &SetterPrime PointerBrand S A -> SetterPrime PointerBrand S A

§Returns

A new SetterPrime instance that is a copy of the original.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::SetterPrime,
};

let s: SetterPrime<RcBrand, (i32, String), i32> =
	SetterPrime::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
let cloned = s.clone();
assert_eq!(cloned.over((42, "hi".to_string()), |x| x + 1), (43, "hi".to_string()));
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, Q, PointerBrand, S, A> Optic<'a, FnBrand<Q>, S, S, A, A> for SetterPrime<'a, PointerBrand, S, A>
where PointerBrand: UnsizedCoercible, Q: UnsizedCoercible, S: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • Q: The pointer brand for the setter.
  • PointerBrand: The type of the structure.
  • S: The type of the focus.
  • A: The pointer brand for the function profunctor.
Source§

fn evaluate( &self, pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, S>

§Type Signature

forall Q PointerBrand S A. (UnsizedCoercible PointerBrand, UnsizedCoercible Q) => (&SetterPrime Q PointerBrand S A, Fn Q A A) -> Fn Q S S

§Parameters
  • &self: The setter instance.
  • pab: The profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};

let s: SetterPrime<RcBrand, (i32, String), i32> =
	SetterPrime::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));

let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x + 1);
let modifier = Optic::<RcFnBrand, _, _, _, _>::evaluate(&s, f);
assert_eq!(modifier((42, "hi".to_string())), (43, "hi".to_string()));
Source§

impl<'a, Q, PointerBrand, S, A> SetterOptic<'a, Q, S, S, A, A> for SetterPrime<'a, PointerBrand, S, A>
where PointerBrand: UnsizedCoercible, Q: UnsizedCoercible, S: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • Q: The pointer brand for the setter.
  • PointerBrand: The type of the structure.
  • S: The type of the focus.
  • A: The pointer brand for the function profunctor.
Source§

fn evaluate( &self, pab: <FnBrand<Q> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <FnBrand<Q> as Kind_266801a817966495>::Of<'a, S, S>

§Type Signature

forall Q PointerBrand S A. (UnsizedCoercible PointerBrand, UnsizedCoercible Q) => (&SetterPrime Q PointerBrand S A, Fn Q A A) -> Fn Q S S

§Parameters
  • &self: The setter instance.
  • pab: The profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use {
	fp_library::{
		brands::{
			optics::*,
			*,
		},
		classes::optics::*,
		functions::*,
		types::optics::*,
	},
	std::rc::Rc,
};

let s: SetterPrime<RcBrand, (i32, String), i32> =
	SetterPrime::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));

let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x + 1);
let modifier: Rc<dyn Fn((i32, String)) -> (i32, String)> =
	SetterOptic::<RcBrand, _, _, _, _>::evaluate(&s, f);
assert_eq!(modifier((42, "hi".to_string())), (43, "hi".to_string()));

Auto Trait Implementations§

§

impl<'a, PointerBrand, S, A> Freeze for SetterPrime<'a, PointerBrand, S, A>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: Freeze,

§

impl<'a, PointerBrand, S, A> RefUnwindSafe for SetterPrime<'a, PointerBrand, S, A>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: RefUnwindSafe,

§

impl<'a, PointerBrand, S, A> Send for SetterPrime<'a, PointerBrand, S, A>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: Send,

§

impl<'a, PointerBrand, S, A> Sync for SetterPrime<'a, PointerBrand, S, A>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: Sync,

§

impl<'a, PointerBrand, S, A> Unpin for SetterPrime<'a, PointerBrand, S, A>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: Unpin,

§

impl<'a, PointerBrand, S, A> UnsafeUnpin for SetterPrime<'a, PointerBrand, S, A>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S + 'a>: UnsafeUnpin,

§

impl<'a, PointerBrand, S, A> UnwindSafe for SetterPrime<'a, PointerBrand, S, A>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn((S, Box<dyn Fn(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> 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.