Skip to main content

Module ref_bifoldable

Module ref_bifoldable 

Source
Expand description

By-reference variant of Bifoldable.

User story: “I want to fold over a bifoldable value without consuming it.”

This trait is for types where the container holds cached or borrowed values accessible by reference. The closures receive &A and &B instead of A and B, avoiding unnecessary moves. A: Clone and B: Clone are required so that default implementations can own values extracted from references.

§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());

Traits§

RefBifoldable
By-reference folding over a bifoldable structure.

Functions§

ref_bi_fold_left
Folds the bifoldable structure from left to right by reference using two step functions.
ref_bi_fold_map
Maps elements of both types to a monoid by reference and combines the results.
ref_bi_fold_right
Folds the bifoldable structure from right to left by reference using two step functions.