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.
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.
Sourcepub fn new(f: <FnBrand as SendCloneFn>::Of<'a, A, A>) -> Self
pub fn new(f: <FnBrand as SendCloneFn>::Of<'a, A, A>) -> Self
Creates a new SendEndofunction.
§Type Signature
forall A. 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.
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
fn clone(&self) -> Self
§Type Signature
forall A. &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)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, FnBrand: SendLiftFn, A: 'a> Debug 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.
impl<'a, FnBrand: SendLiftFn, A: 'a> Debug 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 fmt(&self, fmt: &mut Formatter<'_>) -> Result
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
§Type Signature
forall A. (&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.
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§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.
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
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. (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>
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> UnsafeUnpin 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