pub struct SendEndofunction<'a, FnBrand: SendCloneableFn, A: '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
'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.
§Fields
0: The wrapped thread-safe function.
Tuple Fields§
§0: <FnBrand as SendCloneableFn>::SendOf<'a, A, A>Implementations§
Source§impl<'a, FnBrand: SendCloneableFn, A: 'a> SendEndofunction<'a, FnBrand, A>
§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.
impl<'a, FnBrand: SendCloneableFn, A: 'a> SendEndofunction<'a, FnBrand, A>
§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.
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 A. (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_cloneable_fn_new::<ArcFnBrand, _, _>(
|x: i32| x * 2,
));
assert_eq!(f.0(5), 10);Trait Implementations§
Source§impl<'a, FnBrand: SendCloneableFn, 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 thread-safe cloneable function wrapper.
A: The input and output type of the function.
impl<'a, FnBrand: SendCloneableFn, 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 thread-safe cloneable function wrapper.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
A new SendEndofunction instance that is a copy of the original.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let f = SendEndofunction::<ArcFnBrand, _>::new(send_cloneable_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: SendCloneableFn, 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 thread-safe cloneable function wrapper.
A: The input and output type of the function.
impl<'a, FnBrand: SendCloneableFn, 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 thread-safe cloneable function wrapper.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_cloneable_fn_new::<ArcFnBrand, _, _>(
|x: i32| x * 2,
));
// Debug formatting is available when the inner function type implements Debug.
// Verify the endofunction applies correctly:
assert_eq!(f.0(5), 10);Source§impl<'a, FnBrand: SendCloneableFn, A: 'a> Hash for SendEndofunction<'a, FnBrand, A>
§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.
impl<'a, FnBrand: SendCloneableFn, A: 'a> Hash for SendEndofunction<'a, FnBrand, A>
§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.
Source§fn hash<H: Hasher>(&self, state: &mut H)
fn hash<H: Hasher>(&self, state: &mut H)
§Type Signature
forall A H. Hasher H => (&SendEndofunction FnBrand A, &mut H) -> ()
§Type Parameters
H: The type of the hasher.
§Parameters
&self: The function to hash.state: The hasher state to update.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let f = SendEndofunction::<ArcFnBrand, _>::new(send_cloneable_fn_new::<ArcFnBrand, _, _>(
|x: i32| x * 2,
));
// Hash is available when the inner function type implements Hash.
// Verify the endofunction applies correctly:
assert_eq!(f.0(5), 10);Source§impl<'a, FnBrand: 'a + SendCloneableFn, 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 thread-safe cloneable function wrapper.
A: The input and output type of the function.
impl<'a, FnBrand: 'a + SendCloneableFn, 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 thread-safe cloneable function wrapper.A: The input and output type of the function.
Source§fn empty() -> Self
fn empty() -> Self
The identity element.
This method returns the identity endofunction, which wraps the identity function.
§Type Signature
forall A. () -> 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: SendCloneableFn, A: 'a> Ord for SendEndofunction<'a, FnBrand, A>
§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.
impl<'a, FnBrand: SendCloneableFn, A: 'a> Ord for SendEndofunction<'a, FnBrand, A>
§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.
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
§Type Signature
forall A. (&SendEndofunction FnBrand A, &SendEndofunction FnBrand A) -> std
§Parameters
&self: The function to compare.other: The other function to compare to.
§Returns
The ordering of the values.
§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 * 2,
));
// Ord is available when the inner function type implements Ord.
// Both produce the same output for the same input:
assert_eq!(f.0(5), g.0(5));1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a, FnBrand: SendCloneableFn, A: 'a> PartialEq for SendEndofunction<'a, FnBrand, A>
§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.
impl<'a, FnBrand: SendCloneableFn, A: 'a> PartialEq for SendEndofunction<'a, FnBrand, A>
§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.
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
§Type Signature
forall A. (&SendEndofunction FnBrand A, &SendEndofunction FnBrand A) -> bool
§Parameters
&self: The function to compare.other: The other function to compare to.
§Returns
True if the values are equal, false otherwise.
§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 * 2,
));
// PartialEq is available when the inner function type implements PartialEq.
// Both produce the same output for the same input:
assert_eq!(f.0(5), g.0(5));Source§impl<'a, FnBrand: SendCloneableFn, A: 'a> PartialOrd for SendEndofunction<'a, FnBrand, A>
§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.
impl<'a, FnBrand: SendCloneableFn, A: 'a> PartialOrd for SendEndofunction<'a, FnBrand, A>
§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.
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
§Type Signature
forall A. (&SendEndofunction FnBrand A, &SendEndofunction FnBrand A) -> Option std
§Parameters
&self: The function to compare.other: The other function to compare to.
§Returns
An ordering if the values can be compared, none otherwise.
§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 * 2,
));
// PartialOrd is available when the inner function type implements PartialOrd.
// Both produce the same output for the same input:
assert_eq!(f.0(5), g.0(5));Source§impl<'a, FnBrand: 'a + SendCloneableFn, 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 thread-safe cloneable function wrapper.
A: The input and output type of the function.
impl<'a, FnBrand: 'a + SendCloneableFn, 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 thread-safe cloneable function wrapper.A: The input and output type of the function.
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 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_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: 'a> Eq for SendEndofunction<'a, FnBrand, A>
§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.
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