Skip to main content

FoldLeftWithIndexDispatch

Trait FoldLeftWithIndexDispatch 

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

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

Fn(Brand::Index, B, A) -> B resolves to Val, Fn(Brand::Index, 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_with_index 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_with_index::<RcFnBrand, VecBrand, _, _, _, _>(
	|i, acc: String, x: i32| format!("{acc}{i}:{x},"),
	String::new(),
	vec![10, 20, 30],
);
assert_eq!(result, "0:10,1:20,2:30,");

Implementors§

Source§

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

Routes Fn(Brand::Index, B, &A) -> B closures to RefFoldableWithIndex::ref_fold_left_with_index.

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> FoldLeftWithIndexDispatch<'a, FnBrand, Brand, A, B, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Val> for F
where Brand: FoldableWithIndex, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a, Brand::Index: 'a, F: Fn(Brand::Index, B, A) -> B + 'a,

Routes Fn(Brand::Index, B, A) -> B closures to FoldableWithIndex::fold_left_with_index.

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