Skip to main content

fold_right

Function fold_right 

Source
pub fn fold_right<'a, FnBrand, FA, A: 'a + Clone, B: 'a, Brand>(
    func: impl FoldRightDispatch<'a, FnBrand, Brand, A, B, FA, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,
    initial: B,
    fa: FA,
) -> B
Expand description

Folds a structure from the right, 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_right with a turbofish.

§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 (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_right::<RcFnBrand, _, _, _, _>(|a, b| a + b, 0, vec![1, 2, 3]);
assert_eq!(result, 6);