pub trait SendRefFoldableWithIndex:
SendRefFoldable
+ WithIndex
+ Kind_cdc7cd43dac7585f {
// Provided methods
fn send_ref_fold_map_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, R: Monoid + Send + Sync + 'a>(
f: impl Fn(Self::Index, &A) -> R + Send + Sync + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> R
where FnBrand: SendLiftFn + 'a,
Self::Index: Send + Sync + 'a { ... }
fn send_ref_fold_right_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, B: Send + Sync + 'a>(
func: impl Fn(Self::Index, &A, B) -> B + Send + Sync + 'a,
initial: B,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> B
where FnBrand: SendLiftFn + 'a,
Self::Index: Send + Sync + 'a { ... }
fn send_ref_fold_left_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, B: Send + Sync + 'a>(
func: impl Fn(Self::Index, B, &A) -> B + Send + Sync + 'a,
initial: B,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> B
where FnBrand: SendLiftFn + 'a,
Self::Index: Send + Sync + 'a { ... }
}Expand description
Thread-safe by-reference folding with index over a structure.
Similar to RefFoldableWithIndex, but closures and elements must be Send + Sync.
All three methods (send_ref_fold_map_with_index, send_ref_fold_right_with_index,
send_ref_fold_left_with_index) have default implementations in terms of each other,
so implementors only need to provide one.
Provided Methods§
Sourcefn send_ref_fold_map_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, R: Monoid + Send + Sync + 'a>(
f: impl Fn(Self::Index, &A) -> R + Send + Sync + 'a,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> R
fn send_ref_fold_map_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, R: Monoid + Send + Sync + 'a>( f: impl Fn(Self::Index, &A) -> R + Send + Sync + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> R
Maps each element to a monoid by reference with index (thread-safe).
§Type Signature
forall A R. Monoid R => ((Self, &A) -> R, &Self A) -> R
§Type Parameters
'a: The lifetime of the values.FnBrand: The brand of the cloneable function to use.A: The type of the elements.R: The monoid type.
§Parameters
f: The function to apply to each element’s index and reference.fa: The structure to fold over.
§Returns
The combined result.
§Examples
use fp_library::{
brands::*,
classes::send_ref_foldable_with_index::SendRefFoldableWithIndex,
types::*,
};
let lazy = ArcLazy::new(|| 42);
let result =
<LazyBrand<ArcLazyConfig> as SendRefFoldableWithIndex>::send_ref_fold_map_with_index::<
ArcFnBrand,
_,
_,
>(|_, x: &i32| x.to_string(), &lazy);
assert_eq!(result, "42");Sourcefn send_ref_fold_right_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, B: Send + Sync + 'a>(
func: impl Fn(Self::Index, &A, B) -> B + Send + Sync + 'a,
initial: B,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> B
fn send_ref_fold_right_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, B: Send + Sync + 'a>( func: impl Fn(Self::Index, &A, B) -> B + Send + Sync + 'a, initial: B, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
Folds the structure from the right by reference with index (thread-safe).
§Type Signature
forall A B. ((Self, &A, B) -> B, B, &Self A) -> B
§Type Parameters
'a: The lifetime of the values.FnBrand: The brand of the cloneable function to use.A: The type of the elements.B: The type of the accumulator.
§Parameters
func: The function to apply to each element’s index, reference, and accumulator.initial: The initial value of the accumulator.fa: The structure to fold over.
§Returns
The final accumulator value.
§Examples
use fp_library::{
brands::*,
classes::send_ref_foldable_with_index::SendRefFoldableWithIndex,
types::*,
};
let lazy = ArcLazy::new(|| 10);
let result =
<LazyBrand<ArcLazyConfig> as SendRefFoldableWithIndex>::send_ref_fold_right_with_index::<
ArcFnBrand,
_,
_,
>(|_, x: &i32, acc: i32| acc + *x, 0, &lazy);
assert_eq!(result, 10);Sourcefn send_ref_fold_left_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, B: Send + Sync + 'a>(
func: impl Fn(Self::Index, B, &A) -> B + Send + Sync + 'a,
initial: B,
fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> B
fn send_ref_fold_left_with_index<'a, FnBrand, A: Send + Sync + 'a + Clone, B: Send + Sync + 'a>( func: impl Fn(Self::Index, B, &A) -> B + Send + Sync + 'a, initial: B, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
Folds the structure from the left by reference with index (thread-safe).
§Type Signature
forall A B. ((Self, B, &A) -> B, B, &Self A) -> B
§Type Parameters
'a: The lifetime of the values.FnBrand: The brand of the cloneable function to use.A: The type of the elements.B: The type of the accumulator.
§Parameters
func: The function to apply to the accumulator, each element’s index, and reference.initial: The initial value of the accumulator.fa: The structure to fold over.
§Returns
The final accumulator value.
§Examples
use fp_library::{
brands::*,
classes::send_ref_foldable_with_index::SendRefFoldableWithIndex,
types::*,
};
let lazy = ArcLazy::new(|| 10);
let result =
<LazyBrand<ArcLazyConfig> as SendRefFoldableWithIndex>::send_ref_fold_left_with_index::<
ArcFnBrand,
_,
_,
>(|_, acc: i32, x: &i32| acc + *x, 0, &lazy);
assert_eq!(result, 10);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.