Expand description
Dispatch for bifoldable operations:
Bifoldable and
RefBifoldable.
Provides the following dispatch traits and unified free functions:
BiFoldLeftDispatch+explicit::bi_fold_leftBiFoldRightDispatch+explicit::bi_fold_rightBiFoldMapDispatch+explicit::bi_fold_map
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§
- BiFold
Left Dispatch - Trait that routes a bi_fold_left operation to the appropriate type class method.
- BiFold
MapDispatch - Trait that routes a bi_fold_map operation to the appropriate type class method.
- BiFold
Right Dispatch - 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.