Skip to main content

Module foldable

Module foldable 

Source
Expand description

Dispatch for Foldable::fold_right, fold_left, fold_map, and their by-reference counterparts in RefFoldable.

§Examples

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

// By-value fold_right (Vec)
let result = fold_right::<RcFnBrand, VecBrand, _, _, _, _>(|a, b| a + b, 0, vec![1, 2, 3]);
assert_eq!(result, 6);

// By-ref fold_right (Lazy, closure receives &A)
let lazy = RcLazy::new(|| 10);
let result =
	fold_right::<RcFnBrand, LazyBrand<RcLazyConfig>, _, _, _, _>(|a: &i32, b| *a + b, 5, &lazy);
assert_eq!(result, 15);

Modules§

explicit
Explicit dispatch functions requiring a Brand turbofish.

Traits§

FoldLeftDispatch
Trait that routes a fold_left operation to the appropriate type class method.
FoldMapDispatch
Trait that routes a fold_map operation to the appropriate type class method.
FoldRightDispatch
Trait that routes a fold_right operation to the appropriate type class method.

Functions§

fold_left
Folds a structure from the left, inferring the brand from the container type.
fold_map
Maps values to a monoid and combines them, inferring the brand from the container type.
fold_right
Folds a structure from the right, inferring the brand from the container type.