Skip to main content

SendEndofunction

Struct SendEndofunction 

Source
pub struct SendEndofunction<'a, FnBrand: SendLiftFn, A: 'a>(pub <FnBrand as SendCloneFn>::Of<'a, A, A>);
Expand description

A thread-safe wrapper for endofunctions that enables monoidal operations.

SendEndofunction a represents a function a -> a wrapped in an Arc<dyn Fn>.

It exists to provide a monoid instance where:

  • The binary operation append is function composition.
  • The identity element empty is the identity function.

This is the Send + Sync counterpart of Endofunction.

§Type Parameters

  • 'a: The lifetime of the function and its captured data.
  • FnBrand: The brand of the thread-safe cloneable function wrapper.
  • A: The input and output type of the function.

Tuple Fields§

§0: <FnBrand as SendCloneFn>::Of<'a, A, A>

The wrapped function.

Implementations§

Source§

impl<'a, FnBrand: SendLiftFn, A: 'a> SendEndofunction<'a, FnBrand, A>

§Type Parameters
  • 'a: The lifetime of the function and its captured data.
  • FnBrand: The brand of the function (e.g., ArcFnBrand).
  • A: The input and output type of the function.
Source

pub fn new(f: <FnBrand as SendCloneFn>::Of<'a, A, A>) -> Self

Creates a new SendEndofunction.

§Type Signature

forall A. SendLiftFn FnBrand => FnBrand A A -> SendEndofunction FnBrand A

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

A new SendEndofunction.

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

let f =
	SendEndofunction::<ArcFnBrand, _>::new(send_lift_fn_new::<ArcFnBrand, _, _>(|x: i32| {
		x * 2
	}));
assert_eq!(f.0(5), 10);

Trait Implementations§

Source§

impl<'a, FnBrand: SendLiftFn, A: 'a> Clone for SendEndofunction<'a, FnBrand, A>

§Type Parameters
  • 'a: The lifetime of the function and its captured data.
  • FnBrand: The brand of the function (e.g., ArcFnBrand).
  • A: The input and output type of the function.
Source§

fn clone(&self) -> Self

§Type Signature

forall A. SendLiftFn FnBrand => &SendEndofunction FnBrand A -> SendEndofunction FnBrand A

§Returns

The cloned endofunction.

§Examples
use fp_library::{
	brands::*,
	functions::*,
	types::*,
};
let f =
	SendEndofunction::<ArcFnBrand, _>::new(send_lift_fn_new::<ArcFnBrand, _, _>(|x: i32| {
		x * 2
	}));
let cloned = f.clone();
assert_eq!(cloned.0(5), 10);
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, FnBrand: SendLiftFn, A: 'a> Debug for SendEndofunction<'a, FnBrand, A>
where <FnBrand as SendCloneFn>::Of<'a, A, A>: Debug,

§Type Parameters
  • 'a: The lifetime of the function and its captured data.
  • FnBrand: The brand of the function (e.g., ArcFnBrand).
  • A: The input and output type of the function.
Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

§Type Signature

forall A. SendLiftFn FnBrand => (&SendEndofunction FnBrand A, &mut Formatter) -> fmt

§Parameters
  • &self: The function to format.
  • fmt: The formatter to use.
§Returns

The result of the formatting operation.

§Examples
use fp_library::{
	brands::*,
	functions::*,
	types::*,
};
let f =
	SendEndofunction::<ArcFnBrand, _>::new(send_lift_fn_new::<ArcFnBrand, _, _>(|x: i32| {
		x * 2
	}));
assert_eq!(f.0(5), 10);
Source§

impl<'a, FnBrand: 'a + SendLiftFn, A: 'a + Send + Sync> Monoid for SendEndofunction<'a, FnBrand, A>

§Type Parameters
  • 'a: The lifetime of the function and its captured data.
  • FnBrand: The brand of the function (e.g., ArcFnBrand).
  • A: The input and output type of the function.
Source§

fn empty() -> Self

Returns the identity endofunction.

§Type Signature

forall A. SendLiftFn FnBrand => () -> SendEndofunction FnBrand A

§Returns

The identity endofunction.

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

let id = empty::<SendEndofunction<ArcFnBrand, i32>>();
assert_eq!(id.0(5), 5);
Source§

impl<'a, FnBrand: 'a + SendLiftFn, A: 'a + Send + Sync> Semigroup for SendEndofunction<'a, FnBrand, A>

§Type Parameters
  • 'a: The lifetime of the function and its captured data.
  • FnBrand: The brand of the function (e.g., ArcFnBrand).
  • A: The input and output type of the function.
Source§

fn append(a: Self, b: Self) -> Self

Composes two endofunctions.

append(f, g) results in f . g (read as “f after g”), meaning g is applied first, then f.

§Type Signature

forall A. SendLiftFn FnBrand => (SendEndofunction FnBrand A, SendEndofunction FnBrand A) -> SendEndofunction FnBrand A

§Parameters
  • a: The second function to apply (the outer function).
  • b: The first function to apply (the inner function).
§Returns

The composed function a . b.

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

let f =
	SendEndofunction::<ArcFnBrand, _>::new(send_lift_fn_new::<ArcFnBrand, _, _>(|x: i32| {
		x * 2
	}));
let g =
	SendEndofunction::<ArcFnBrand, _>::new(send_lift_fn_new::<ArcFnBrand, _, _>(|x: i32| {
		x + 1
	}));

// f(g(x)) = (x + 1) * 2
let h = append::<_>(f, g);
assert_eq!(h.0(5), 12);

Auto Trait Implementations§

§

impl<'a, FnBrand, A> Freeze for SendEndofunction<'a, FnBrand, A>
where <FnBrand as SendCloneFn>::Of<'a, A, A>: Freeze,

§

impl<'a, FnBrand, A> RefUnwindSafe for SendEndofunction<'a, FnBrand, A>
where <FnBrand as SendCloneFn>::Of<'a, A, A>: RefUnwindSafe,

§

impl<'a, FnBrand, A> Send for SendEndofunction<'a, FnBrand, A>

§

impl<'a, FnBrand, A> Sync for SendEndofunction<'a, FnBrand, A>

§

impl<'a, FnBrand, A> Unpin for SendEndofunction<'a, FnBrand, A>
where <FnBrand as SendCloneFn>::Of<'a, A, A>: Unpin,

§

impl<'a, FnBrand, A> UnsafeUnpin for SendEndofunction<'a, FnBrand, A>
where <FnBrand as SendCloneFn>::Of<'a, A, A>: UnsafeUnpin,

§

impl<'a, FnBrand, A> UnwindSafe for SendEndofunction<'a, FnBrand, A>
where <FnBrand as SendCloneFn>::Of<'a, A, 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.