pub fn fold_right<'a, FnBrand, Brand: Kind_cdc7cd43dac7585f, A: 'a + Clone, B: 'a, FA, Marker>(
func: impl FoldRightDispatch<'a, FnBrand, Brand, A, B, FA, Marker>,
initial: B,
fa: FA,
) -> BExpand description
Folds a structure from the right.
Dispatches to Foldable::fold_right or RefFoldable::ref_fold_right
based on whether the closure takes A or &A.
The Marker and FA type parameters are inferred automatically by the
compiler from the closure’s argument type and the container argument.
§Type Signature
forall Brand A B. Foldable Brand => ((A, B) -> B, B, Brand A) -> B
§Type Parameters
'a: The lifetime of the values.FnBrand: The brand of the cloneable function to use.Brand: The brand of the foldable structure.A: The type of the elements.B: The type of the accumulator.FA: The container type (owned or borrowed), inferred from the argument.Marker: Dispatch marker type, inferred automatically.
§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::explicit::*,
types::*,
};
// By-value
let result = fold_right::<RcFnBrand, VecBrand, _, _, _, _>(|a, b| a + b, 0, vec![1, 2, 3]);
assert_eq!(result, 6);
// By-ref
let lazy = RcLazy::new(|| 10);
let result =
fold_right::<RcFnBrand, LazyBrand<RcLazyConfig>, _, _, _, _>(|a: &i32, b| *a + b, 5, &lazy);
assert_eq!(result, 15);