pub struct SendEndofunction<'a, FnBrand: SendCloneableFn, A>(pub <FnBrand as SendCloneableFn>::SendOf<'a, A, A>);Expand description
A thread-safe wrapper for endofunctions (functions from a set to the same set) that enables monoidal operations.
SendEndofunction a represents a function a -> a that is Send + Sync.
It exists to provide a monoid instance where:
- The binary operation append is function composition.
- The identity element empty is the identity function.
The wrapped function can be accessed directly via the .0 field.
§Type Parameters
FnBrand: The brand of the thread-safe cloneable function wrapper.A: The input and output type of the function.
§Fields
0: The wrapped thread-safe function.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let f = SendEndofunction::<ArcFnBrand, _>::new(send_cloneable_fn_new::<ArcFnBrand, _, _>(|x: i32| x * 2));
assert_eq!(f.0(5), 10);Tuple Fields§
§0: <FnBrand as SendCloneableFn>::SendOf<'a, A, A>Implementations§
Source§impl<'a, FnBrand: SendCloneableFn, A> SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: SendCloneableFn, A> SendEndofunction<'a, FnBrand, A>
Sourcepub fn new(f: <FnBrand as SendCloneableFn>::SendOf<'a, A, A>) -> Self
pub fn new(f: <FnBrand as SendCloneableFn>::SendOf<'a, A, A>) -> Self
Creates a new SendEndofunction.
This function wraps a thread-safe function a -> a in a SendEndofunction struct.
§Type Signature
forall fn_brand a. (a -> a) -> SendEndofunction fn_brand a
§Type Parameters
FnBrand: The brand of the function (e.g.,ArcFnBrand).A: The input and output type of the function.
§Parameters
f: The function to wrap.
§Returns
A new SendEndofunction.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let f = SendEndofunction::<ArcFnBrand, _>::new(send_cloneable_fn_new::<ArcFnBrand, _, _>(|x: i32| x * 2));
assert_eq!(f.0(5), 10);Trait Implementations§
Source§impl<'a, FnBrand: SendCloneableFn, A> Clone for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: SendCloneableFn, A> Clone for SendEndofunction<'a, FnBrand, A>
Source§impl<'a, FnBrand: SendCloneableFn, A> Debug for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: SendCloneableFn, A> Debug for SendEndofunction<'a, FnBrand, A>
Source§impl<'a, FnBrand: SendCloneableFn, A> Hash for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: SendCloneableFn, A> Hash for SendEndofunction<'a, FnBrand, A>
Source§impl<'a, FnBrand: 'a + SendCloneableFn, A: 'a + Send + Sync> Monoid for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: 'a + SendCloneableFn, A: 'a + Send + Sync> Monoid for SendEndofunction<'a, FnBrand, A>
Source§fn empty() -> Self
fn empty() -> Self
The identity element.
This method returns the identity endofunction, which wraps the identity function.
§Type Signature
forall fn_brand a. Monoid (SendEndofunction fn_brand a) => () -> SendEndofunction fn_brand 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: SendCloneableFn, A> Ord for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: SendCloneableFn, A> Ord for SendEndofunction<'a, FnBrand, A>
Source§impl<'a, FnBrand: SendCloneableFn, A> PartialEq for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: SendCloneableFn, A> PartialEq for SendEndofunction<'a, FnBrand, A>
Source§impl<'a, FnBrand: SendCloneableFn, A> PartialOrd for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: SendCloneableFn, A> PartialOrd for SendEndofunction<'a, FnBrand, A>
Source§impl<'a, FnBrand: 'a + SendCloneableFn, A: 'a + Send + Sync> Semigroup for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand: 'a + SendCloneableFn, A: 'a + Send + Sync> Semigroup for SendEndofunction<'a, FnBrand, A>
Source§fn append(a: Self, b: Self) -> Self
fn append(a: Self, b: Self) -> Self
The result of combining the two values using the semigroup operation.
This method combines two endofunctions into a single endofunction.
Note that SendEndofunction composition is reversed relative to standard function composition:
append(f, g) results in f . g (read as “f after g”), meaning g is applied first, then f.
§Type Signature
forall fn_brand a. Semigroup (SendEndofunction fn_brand a) => (SendEndofunction fn_brand a, SendEndofunction fn_brand a) -> SendEndofunction fn_brand 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_cloneable_fn_new::<ArcFnBrand, _, _>(|x: i32| x * 2));
let g = SendEndofunction::<ArcFnBrand, _>::new(send_cloneable_fn_new::<ArcFnBrand, _, _>(|x: i32| x + 1));
// f(g(x)) = (x + 1) * 2
let h = append::<_>(f, g);
assert_eq!(h.0(5), 12);impl<'a, FnBrand: SendCloneableFn, A> Eq for SendEndofunction<'a, FnBrand, A>
Auto Trait Implementations§
impl<'a, FnBrand, A> Freeze for SendEndofunction<'a, FnBrand, A>
impl<'a, FnBrand, A> RefUnwindSafe for SendEndofunction<'a, FnBrand, A>
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>
impl<'a, FnBrand, A> UnwindSafe for SendEndofunction<'a, FnBrand, A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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