pub fn traverse<'a, FnBrand, FA, A: 'a, B: 'a, F: Kind_cdc7cd43dac7585f, Brand>(
func: impl TraverseDispatch<'a, FnBrand, Brand, A, B, F, FA, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,
ta: FA,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
Brand: Kind_cdc7cd43dac7585f,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>,Expand description
Traverses a structure, inferring the brand from the container type.
The Brand type parameter is inferred from the concrete type of ta
via the InferableBrand trait. FnBrand and F (the applicative brand) must
still be specified explicitly.
Both owned and borrowed containers are supported.
For types with multiple brands, use
explicit::traverse with a turbofish.
§Type Signature
forall Brand A B F. (Traversable Brand, Applicative F) => (A -> F B, Brand A) -> F (Brand B)
§Type Parameters
'a: The lifetime of the values.FnBrand: The brand of the cloneable function to use (must be specified explicitly).FA: The container type (owned or borrowed). Brand is inferred from this.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 (must be specified explicitly).Brand: The brand, inferred via InferableBrand from FA and the closure’s input type.
§Parameters
func: The function to apply to each element, returning a value in an applicative context.ta: The traversable structure (owned for Val, borrowed for Ref).
§Returns
The structure wrapped in the applicative context.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let y = traverse::<RcFnBrand, _, _, _, OptionBrand, _>(|x: i32| Some(x * 2), Some(5));
assert_eq!(y, Some(Some(10)));