Skip to main content

FoldLeftDispatch

Trait FoldLeftDispatch 

Source
pub trait FoldLeftDispatch<'a, FnBrand, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, FA, Marker> {
    // Required method
    fn dispatch(self, initial: B, fa: FA) -> B;
}
Expand description

Trait that routes a fold_left operation to the appropriate type class method.

Fn(B, A) -> B resolves to Val, Fn(B, &A) -> B resolves to Ref. The FA type parameter is inferred from the container argument: owned for Val dispatch, borrowed for Ref dispatch.

§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.

Required Methods§

Source

fn dispatch(self, initial: B, fa: FA) -> B

Perform the dispatched fold_left operation.

§Type Signature

(self, B, FA) -> B

§Parameters
  • self: The closure implementing this dispatch.
  • initial: The initial accumulator value.
  • fa: The structure to fold.
§Returns

The final accumulator value.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let result = fold_left::<RcFnBrand, VecBrand, _, _, _, _>(|b, a| b + a, 0, vec![1, 2, 3]);
assert_eq!(result, 6);

Implementors§

Source§

impl<'a, 'b, FnBrand, Brand, A, B, F> FoldLeftDispatch<'a, FnBrand, Brand, A, B, &'b <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Ref> for F
where Brand: RefFoldable, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a, F: Fn(B, &A) -> B + 'a,

Routes Fn(B, &A) -> B closures to RefFoldable::ref_fold_left.

The container must be passed by reference (&fa).

§Type Parameters
  • 'a: The lifetime.
  • 'b: The borrow lifetime.
  • FnBrand: The cloneable function brand.
  • Brand: The foldable brand.
  • A: The element type.
  • B: The accumulator type.
  • F: The closure type.
Source§

impl<'a, FnBrand, Brand, A, B, F> FoldLeftDispatch<'a, FnBrand, Brand, A, B, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Val> for F
where Brand: Foldable, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a, F: Fn(B, A) -> B + 'a,

Routes Fn(B, A) -> B closures to Foldable::fold_left.

§Type Parameters
  • 'a: The lifetime.
  • FnBrand: The cloneable function brand.
  • Brand: The foldable brand.
  • A: The element type.
  • B: The accumulator type.
  • F: The closure type.