pub fn ref_traverse<'a, Brand: RefTraversable, FnBrand, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
func: impl Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,
ta: &<Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
FnBrand: LiftFn + 'a,
<Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
<F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,Expand description
Maps each element by reference to a computation, evaluates them, and combines the results.
Free function version that dispatches to the type class’ associated function.
§Type Signature
forall Brand A B F. (RefTraversable Brand, Applicative F) => (&A -> F B, &Brand A) -> F (Brand B)
§Type Parameters
'a: The lifetime of the elements.Brand: The brand of the structure.FnBrand: The brand of the cloneable function wrapper.A: The type of the input elements.B: The type of the output elements.F: The applicative functor brand.
§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()]));