Skip to main content

BiFoldLeftDispatch

Trait BiFoldLeftDispatch 

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

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

(Fn(C, A) -> C, Fn(C, B) -> C) resolves to Val, (Fn(C, &A) -> C, Fn(C, &B) -> C) resolves to Ref.

§Type Parameters

  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • Brand: The brand of the bifoldable structure.
  • A: The type of the first-position elements.
  • B: The type of the second-position elements.
  • C: 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, z: C, fa: FA) -> C

Perform the dispatched bi_fold_left operation.

§Type Signature

(self, C, FA) -> C

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

The final accumulator value.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let x: Result<i32, i32> = Ok(5);
let y = bi_fold_left::<RcFnBrand, ResultBrand, _, _, _, _, _>(
	(|acc, e| acc - e, |acc, s| acc + s),
	10,
	x,
);
assert_eq!(y, 15);

Implementations on Foreign Types§

Source§

impl<'a, 'b, FnBrand, Brand, A, B, C, F, G> BiFoldLeftDispatch<'a, FnBrand, Brand, A, B, C, &'b <Brand as Kind_266801a817966495>::Of<'a, A, B>, Ref> for (F, G)
where Brand: RefBifoldable, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a + Clone, C: 'a, F: Fn(C, &A) -> C + 'a, G: Fn(C, &B) -> C + 'a,

Routes (Fn(C, &A) -> C, Fn(C, &B) -> C) closure tuples to RefBifoldable::ref_bi_fold_left.

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

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

fn dispatch( self, z: C, fa: &'b <Brand as Kind_266801a817966495>::Of<'a, A, B>, ) -> C

§Type Signature

forall Brand A B C. (RefBifoldable Brand, LiftFn FnBrand) => (((C, &A) -> C, (C, &B) -> C), C, &Brand A B) -> C

§Parameters
  • self: The closure tuple.
  • z: The initial accumulator value.
  • fa: A reference to the structure to fold.
§Returns

The final accumulator value.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let x: Result<i32, i32> = Ok(5);
let y = bi_fold_left::<RcFnBrand, ResultBrand, _, _, _, _, _>(
	(|acc, e: &i32| acc - *e, |acc, s: &i32| acc + *s),
	10,
	&x,
);
assert_eq!(y, 15);
Source§

impl<'a, FnBrand, Brand, A, B, C, F, G> BiFoldLeftDispatch<'a, FnBrand, Brand, A, B, C, <Brand as Kind_266801a817966495>::Of<'a, A, B>, Val> for (F, G)
where Brand: Bifoldable, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a + Clone, C: 'a, F: Fn(C, A) -> C + 'a, G: Fn(C, B) -> C + 'a,

Routes (Fn(C, A) -> C, Fn(C, B) -> C) closure tuples to Bifoldable::bi_fold_left.

§Type Parameters
  • 'a: The lifetime.
  • FnBrand: The cloneable function brand.
  • Brand: The bifoldable brand.
  • A: The first element type.
  • B: The second element type.
  • C: The accumulator type.
  • F: The first closure type.
  • G: The second closure type.
Source§

fn dispatch(self, z: C, fa: <Brand as Kind_266801a817966495>::Of<'a, A, B>) -> C

§Type Signature

forall Brand A B C. (Bifoldable Brand, LiftFn FnBrand) => (((C, A) -> C, (C, B) -> C), C, Brand A B) -> C

§Parameters
  • self: The closure tuple.
  • z: The initial accumulator value.
  • fa: The structure to fold.
§Returns

The final accumulator value.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let x: Result<i32, i32> = Ok(5);
let y = bi_fold_left::<RcFnBrand, ResultBrand, _, _, _, _, _>(
	(|acc, e| acc - e, |acc, s| acc + s),
	10,
	x,
);
assert_eq!(y, 15);

Implementors§