pub fn fold_left<'a, FnBrand, FA, A: 'a + Clone, B: 'a, Brand>(
func: impl FoldLeftDispatch<'a, FnBrand, Brand, A, B, FA, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,
initial: B,
fa: FA,
) -> Bwhere
Brand: Kind_cdc7cd43dac7585f,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>,Expand description
Folds a structure from the left, inferring the brand from the container type.
The Brand type parameter is inferred from the concrete type of fa
via the InferableBrand trait. FnBrand must still be specified explicitly.
Both owned and borrowed containers are supported.
For types with multiple brands, use
explicit::fold_left with a turbofish.
§Type Signature
forall Brand A B. Foldable Brand => ((B, A) -> B, B, Brand A) -> 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.B: The type of the accumulator.Brand: The brand, inferred via InferableBrand from FA and the element type.
§Parameters
func: The folding function.initial: The initial accumulator value.fa: The structure to fold (owned for Val, borrowed for Ref).
§Returns
The final accumulator value.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let result = fold_left::<RcFnBrand, _, _, _, _>(|b, a| b + a, 0, vec![1, 2, 3]);
assert_eq!(result, 6);