pub trait RefTraversable:
RefFunctor
+ RefFoldable
+ Kind_cdc7cd43dac7585f {
// Required method
fn ref_traverse<'a, FnBrand, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
func: impl Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
<F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone;
}Expand description
By-reference traversal of structures.
Similar to Traversable, but the closure receives &A instead of A.
This enables traversing collections by reference without consuming elements,
or traversing memoized types that only provide &A access.
ref_traverse is the required method.
Required Methods§
Sourcefn ref_traverse<'a, FnBrand, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
func: impl Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
<F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
fn ref_traverse<'a, FnBrand, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
func: impl Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,
ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
FnBrand: LiftFn + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
<F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
Maps each element by reference to a computation, evaluates them, and combines the results.
§Type Signature
forall A B F. (Applicative F, LiftFn FnBrand) => (&A -> F B, &Self A) -> F (Self B)
§Type Parameters
'a: The lifetime of the elements.FnBrand: The brand of the cloneable function wrapper.A: The type of the elements in the input structure.B: The type of the elements in the output structure.F: The applicative functor brand for the computation.
§Parameters
func: The function to apply to each element reference.ta: The structure to traverse.
§Returns
The combined result in the applicative context.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let v = vec![1, 2, 3];
let result: Option<Vec<String>> =
ref_traverse::<VecBrand, RcFnBrand, _, _, OptionBrand>(|x: &i32| Some(x.to_string()), &v);
assert_eq!(result, Some(vec!["1".to_string(), "2".to_string(), "3".to_string()]));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.
Implementors§
impl RefTraversable for CatListBrand
impl RefTraversable for IdentityBrand
impl RefTraversable for OptionBrand
impl RefTraversable for Tuple1Brand
impl RefTraversable for VecBrand
impl<E: Clone + 'static> RefTraversable for ResultErrAppliedBrand<E>
§Type Parameters
E: The error type.
impl<First: Clone + 'static> RefTraversable for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: Clone + 'static> RefTraversable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<Second: Clone + 'static> RefTraversable for PairSecondAppliedBrand<Second>
§Type Parameters
Second: The type of the second value in the pair.
impl<Second: Clone + 'static> RefTraversable for Tuple2SecondAppliedBrand<Second>
§Type Parameters
Second: The type of the second value in the tuple.
impl<T: Clone + 'static> RefTraversable for ResultOkAppliedBrand<T>
§Type Parameters
T: The success type.