Skip to main content

Forget

Struct Forget 

Source
pub struct Forget<'a, PointerBrand, R, A, B>(pub <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, A, R>, _)
where
    PointerBrand: UnsizedCoercible,
    R: 'a,
    A: 'a;
Expand description

The Forget profunctor.

Forget<P, R, A, B> is a profunctor that ignores its second type argument B and instead stores a function from A to R.

§Type Parameters

  • 'a: The lifetime of the values.
  • PointerBrand: The pointer brand.
  • R: The return type of the function.
  • A: The input type of the function.
  • B: The ignored type.

Tuple Fields§

§0: <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, A, R>

Implementations§

Source§

impl<'a, PointerBrand, R, A, B> Forget<'a, PointerBrand, R, A, B>
where PointerBrand: UnsizedCoercible, R: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The pointer brand.
  • R: The return type of the function.
  • A: The input type of the function.
  • B: The ignored type.
Source

pub fn new(f: impl Fn(A) -> R + 'a) -> Self

Creates a new Forget instance.

§Type Signature

forall PointerBrand R A B. UnsizedCoercible PointerBrand => (A -> R) -> Forget PointerBrand R A B

§Parameters
  • f: The function to wrap.
§Returns

A new instance of the type.

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

let forget = Forget::<RcBrand, i32, String, i32>::new(|s: String| s.len() as i32);
// Access via the underlying function wrapper, which implements Deref
assert_eq!((forget.0)("hello".to_string()), 5);
Source

pub fn run(&self, a: A) -> R

Runs the Forget profunctor on an input.

§Type Signature

forall PointerBrand R A B. UnsizedCoercible PointerBrand => (&Forget PointerBrand R A B, A) -> R

§Parameters
  • &self: The forget instance.
  • a: The input value.
§Returns

The result of applying the underlying function to the input.

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

let forget = Forget::<RcBrand, i32, String, i32>::new(|s: String| s.len() as i32);
assert_eq!(forget.run("hello".to_string()), 5);

Trait Implementations§

Source§

impl<'a, PointerBrand, R, A, B> Clone for Forget<'a, PointerBrand, R, A, B>
where PointerBrand: UnsizedCoercible, R: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The pointer brand.
  • R: The return type of the function.
  • A: The input type of the function.
  • B: The ignored type.
Source§

fn clone(&self) -> Self

§Type Signature

forall PointerBrand R A B. UnsizedCoercible PointerBrand => &Forget PointerBrand R A B -> Forget PointerBrand R A B

§Returns

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

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

let forget = Forget::<RcBrand, i32, String, i32>::new(|s: String| s.len() as i32);
let cloned = forget.clone();
assert_eq!(cloned.run("hello".to_string()), 5);
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<'a, PointerBrand, R, A, B> Freeze for Forget<'a, PointerBrand, R, A, B>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(A) -> R + 'a>: Freeze,

§

impl<'a, PointerBrand, R, A, B> RefUnwindSafe for Forget<'a, PointerBrand, R, A, B>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(A) -> R + 'a>: RefUnwindSafe, B: RefUnwindSafe,

§

impl<'a, PointerBrand, R, A, B> Send for Forget<'a, PointerBrand, R, A, B>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(A) -> R + 'a>: Send, B: Send,

§

impl<'a, PointerBrand, R, A, B> Sync for Forget<'a, PointerBrand, R, A, B>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(A) -> R + 'a>: Sync, B: Sync,

§

impl<'a, PointerBrand, R, A, B> Unpin for Forget<'a, PointerBrand, R, A, B>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(A) -> R + 'a>: Unpin, B: Unpin,

§

impl<'a, PointerBrand, R, A, B> UnsafeUnpin for Forget<'a, PointerBrand, R, A, B>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(A) -> R + 'a>: UnsafeUnpin,

§

impl<'a, PointerBrand, R, A, B> UnwindSafe for Forget<'a, PointerBrand, R, A, B>
where <PointerBrand as RefCountedPointer>::CloneableOf<'a, dyn Fn(A) -> R + 'a>: UnwindSafe, B: 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.