pub struct SendThunkBrand;Expand description
Brand for SendThunk.
Thread-safe counterpart of ThunkBrand. The inner closure is Send,
enabling deferred computation across thread boundaries.
§HKT limitations
SendThunkBrand does not implement Functor,
Monad, or any other HKT type-class traits.
Those traits accept closure parameters as impl Fn/impl FnOnce without a
Send bound, so there is no way to guarantee that the closures passed to
map, bind, etc. are safe to store inside a Send thunk. Use
ThunkBrand when HKT polymorphism is needed, or work with SendThunk
directly through its inherent methods.
Trait Implementations§
Source§impl Clone for SendThunkBrand
impl Clone for SendThunkBrand
Source§fn clone(&self) -> SendThunkBrand
fn clone(&self) -> SendThunkBrand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SendThunkBrand
impl Debug for SendThunkBrand
Source§impl Default for SendThunkBrand
impl Default for SendThunkBrand
Source§fn default() -> SendThunkBrand
fn default() -> SendThunkBrand
Source§impl Foldable for SendThunkBrand
impl Foldable for SendThunkBrand
Source§fn fold_right<'a, FnBrand, A: 'a + Clone, B: 'a>(
func: impl Fn(A, B) -> B + 'a,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
FnBrand: CloneFn + 'a,
fn fold_right<'a, FnBrand, A: 'a + Clone, B: 'a>(
func: impl Fn(A, B) -> B + 'a,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
FnBrand: CloneFn + 'a,
Folds the SendThunk from the right.
§Type Signature
forall A B. CloneFn FnBrand => ((A, B) -> B, B, SendThunk A) -> B
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.A: The type of the elements in the structure.B: The type of the accumulator.
§Parameters
func: The function to apply to each element and the accumulator.initial: The initial value of the accumulator.fa: TheSendThunkto fold.
§Returns
The final accumulator value.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let thunk = SendThunk::pure(10);
let result =
explicit::fold_right::<RcFnBrand, SendThunkBrand, _, _, _, _>(|a, b| a + b, 5, thunk);
assert_eq!(result, 15);Source§fn fold_left<'a, FnBrand, A: 'a + Clone, B: 'a>(
func: impl Fn(B, A) -> B + 'a,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
FnBrand: CloneFn + 'a,
fn fold_left<'a, FnBrand, A: 'a + Clone, B: 'a>(
func: impl Fn(B, A) -> B + 'a,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
FnBrand: CloneFn + 'a,
Folds the SendThunk from the left.
§Type Signature
forall A B. CloneFn FnBrand => ((B, A) -> B, B, SendThunk A) -> B
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.A: The type of the elements in the structure.B: The type of the accumulator.
§Parameters
func: The function to apply to the accumulator and each element.initial: The initial value of the accumulator.fa: TheSendThunkto fold.
§Returns
The final accumulator value.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let thunk = SendThunk::pure(10);
let result =
explicit::fold_left::<RcFnBrand, SendThunkBrand, _, _, _, _>(|b, a| b + a, 5, thunk);
assert_eq!(result, 15);Source§fn fold_map<'a, FnBrand, A: 'a + Clone, M>(
func: impl Fn(A) -> M + 'a,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> M
fn fold_map<'a, FnBrand, A: 'a + Clone, M>( func: impl Fn(A) -> M + 'a, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
Maps the value to a monoid and returns it.
§Type Signature
forall A M. (Monoid M, CloneFn FnBrand) => (A -> M, SendThunk A) -> M
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.A: The type of the elements in the structure.M: The type of the monoid.
§Parameters
func: The mapping function.fa: TheSendThunkto fold.
§Returns
The monoid value.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let thunk = SendThunk::pure(10);
let result =
explicit::fold_map::<RcFnBrand, SendThunkBrand, _, _, _, _>(|a: i32| a.to_string(), thunk);
assert_eq!(result, "10");Source§impl FoldableWithIndex for SendThunkBrand
impl FoldableWithIndex for SendThunkBrand
Source§fn fold_map_with_index<'a, FnBrand, A: 'a + Clone, R: Monoid>(
f: impl Fn((), A) -> R + 'a,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Rwhere
FnBrand: LiftFn + 'a,
fn fold_map_with_index<'a, FnBrand, A: 'a + Clone, R: Monoid>(
f: impl Fn((), A) -> R + 'a,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Rwhere
FnBrand: LiftFn + 'a,
Folds the send thunk using a monoid, providing the index ().
§Type Signature
forall A R. Monoid R => (((), A) -> R, SendThunk A) -> R
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.A: The type of the value inside the send thunk.R: The monoid type.
§Parameters
f: The function to apply to the value and its index.fa: The send thunk to fold.
§Returns
The monoid value.
§Examples
use fp_library::{
brands::*,
classes::foldable_with_index::FoldableWithIndex,
types::*,
};
let thunk = SendThunk::pure(5);
let result = <SendThunkBrand as FoldableWithIndex>::fold_map_with_index::<RcFnBrand, _, _>(
|_, x: i32| x.to_string(),
thunk,
);
assert_eq!(result, "5");Source§impl Hash for SendThunkBrand
impl Hash for SendThunkBrand
Source§impl<'a, A: 'a> InferableBrand_cdc7cd43dac7585f<'a, SendThunkBrand, A> for SendThunk<'a, A>
Generated InferableBrand_cdc7cd43dac7585f implementation for SendThunk < 'a, A > with brand SendThunkBrand.
impl<'a, A: 'a> InferableBrand_cdc7cd43dac7585f<'a, SendThunkBrand, A> for SendThunk<'a, A>
Generated InferableBrand_cdc7cd43dac7585f implementation for SendThunk < 'a, A > with brand SendThunkBrand.
Source§impl Kind_cdc7cd43dac7585f for SendThunkBrand
Generated implementation of Kind_cdc7cd43dac7585f for SendThunkBrand.
impl Kind_cdc7cd43dac7585f for SendThunkBrand
Generated implementation of Kind_cdc7cd43dac7585f for SendThunkBrand.
Source§impl Ord for SendThunkBrand
impl Ord for SendThunkBrand
Source§fn cmp(&self, other: &SendThunkBrand) -> Ordering
fn cmp(&self, other: &SendThunkBrand) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for SendThunkBrand
impl PartialEq for SendThunkBrand
Source§impl PartialOrd for SendThunkBrand
impl PartialOrd for SendThunkBrand
Source§impl WithIndex for SendThunkBrand
impl WithIndex for SendThunkBrand
impl Copy for SendThunkBrand
impl Eq for SendThunkBrand
impl StructuralPartialEq for SendThunkBrand
Auto Trait Implementations§
impl Freeze for SendThunkBrand
impl RefUnwindSafe for SendThunkBrand
impl Send for SendThunkBrand
impl Sync for SendThunkBrand
impl Unpin for SendThunkBrand
impl UnsafeUnpin for SendThunkBrand
impl UnwindSafe for SendThunkBrand
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