Skip to main content

BiFoldMapDispatch

Trait BiFoldMapDispatch 

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

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

(Fn(A) -> M, Fn(B) -> M) resolves to Val, (Fn(&A) -> M, Fn(&B) -> M) 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.
  • M: The monoid type.
  • FA: The container type (owned or borrowed), inferred from the argument.
  • Marker: Dispatch marker type, inferred automatically.

Required Methods§

Source

fn dispatch(self, fa: FA) -> M

Perform the dispatched bi_fold_map operation.

§Type Signature

(self, FA) -> M

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

The combined monoid value.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let x: Result<i32, i32> = Ok(5);
let y = bi_fold_map::<RcFnBrand, ResultBrand, _, _, _, _, _>(
	(|e: i32| e.to_string(), |s: i32| s.to_string()),
	x,
);
assert_eq!(y, "5".to_string());

Implementations on Foreign Types§

Source§

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

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

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.
  • M: The monoid type.
  • F: The first closure type.
  • G: The second closure type.
Source§

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

§Type Signature

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

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

The combined monoid value.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let x: Result<i32, i32> = Ok(5);
let y = bi_fold_map::<RcFnBrand, ResultBrand, _, _, _, _, _>(
	(|e: &i32| e.to_string(), |s: &i32| s.to_string()),
	&x,
);
assert_eq!(y, "5".to_string());
Source§

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

Routes (Fn(A) -> M, Fn(B) -> M) closure tuples to Bifoldable::bi_fold_map.

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

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

§Type Signature

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

§Parameters
  • self: The closure tuple.
  • fa: The structure to fold.
§Returns

The combined monoid value.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let x: Result<i32, i32> = Ok(5);
let y = bi_fold_map::<RcFnBrand, ResultBrand, _, _, _, _, _>(
	(|e: i32| e.to_string(), |s: i32| s.to_string()),
	x,
);
assert_eq!(y, "5".to_string());

Implementors§