Skip to main content

Module bifoldable

Module bifoldable 

Source
Expand description

Dispatch for bifoldable operations: Bifoldable and RefBifoldable.

Provides the following dispatch traits and unified free functions:

Each routes to the appropriate trait method based on the closures’ argument types.

§Examples

use fp_library::{
	brands::*,
	functions::explicit::*,
};

// bi_fold_left
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);

// bi_fold_right
let x: Result<i32, i32> = Err(3);
let y = bi_fold_right::<RcFnBrand, ResultBrand, _, _, _, _, _>(
	(|e, acc| acc - e, |s, acc| acc + s),
	10,
	x,
);
assert_eq!(y, 7);

// bi_fold_map
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());

Modules§

explicit
Explicit dispatch functions requiring a Brand turbofish.

Traits§

BiFoldLeftDispatch
Trait that routes a bi_fold_left operation to the appropriate type class method.
BiFoldMapDispatch
Trait that routes a bi_fold_map operation to the appropriate type class method.
BiFoldRightDispatch
Trait that routes a bi_fold_right operation to the appropriate type class method.

Functions§

bi_fold_left
Left-folds over a bifoldable structure, inferring the brand from the container type.
bi_fold_map
Folds a bifoldable structure into a monoid, inferring the brand from the container type.
bi_fold_right
Right-folds over a bifoldable structure, inferring the brand from the container type.