Expand description
Dispatch infrastructure for unified free functions that route to either by-value or by-reference trait methods based on the closure’s argument type.
The dispatch system uses marker types (Val and Ref) to select the
appropriate trait at compile time. The compiler infers the marker from the
closure’s argument type: Fn(A) -> B resolves to Val, Fn(&A) -> B
resolves to Ref.
The ClosureMode trait maps each marker to the corresponding dyn Fn
trait object type, used by CloneFn and
SendCloneFn to parameterize the Deref
target of wrapped closures.
§Sub-modules
Each sub-module provides a dispatch trait and unified free function for
a specific type class operation, mirroring the corresponding classes/
module:
functor:FunctorDispatch+mapsemimonad:BindDispatch+bindlift:Lift2Dispatch-Lift5Dispatch+lift2-lift5foldable:FoldRightDispatch,FoldLeftDispatch,FoldMapDispatch+fold_right,fold_left,fold_map
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
types::*,
};
// Closure takes i32 -> dispatches to Functor::map
let y = map::<OptionBrand, _, _, _, _>(|x: i32| x * 2, Some(5));
assert_eq!(y, Some(10));
// Closure takes &i32 -> dispatches to RefFunctor::ref_map
let lazy = RcLazy::pure(10);
let mapped = map::<LazyBrand<RcLazyConfig>, _, _, _, _>(|x: &i32| *x * 2, &lazy);
assert_eq!(*mapped.evaluate(), 20);Modules§
- alt
- Dispatch for
Alt::altandRefAlt::ref_alt. - apply_
first - Dispatch for
ApplyFirst::apply_firstandRefApplyFirst::ref_apply_first. - apply_
second - Dispatch for
ApplySecond::apply_secondandRefApplySecond::ref_apply_second. - bifoldable
- Dispatch for bifoldable operations:
BifoldableandRefBifoldable. - bifunctor
- Dispatch for
Bifunctor::bimapandRefBifunctor::ref_bimap. - bitraversable
- Dispatch for
Bitraversable::bi_traverseandRefBitraversable::ref_bi_traverse. - compactable
- Dispatch for compactable operations:
CompactableandRefCompactable. - contravariant
- Dispatch for
Contravariant::contramap. - filterable
- Dispatch for filterable operations:
FilterableandRefFilterable. - filterable_
with_ index - Dispatch for filterable-with-index operations:
FilterableWithIndexandRefFilterableWithIndex. - foldable
- Dispatch for
Foldable::fold_right,fold_left,fold_map, and their by-reference counterparts inRefFoldable. - foldable_
with_ index - Dispatch for foldable-with-index operations:
FoldableWithIndexandRefFoldableWithIndex. - functor
- Dispatch for
Functor::mapandRefFunctor::ref_map. - functor_
with_ index - Dispatch for
FunctorWithIndex::map_with_indexandRefFunctorWithIndex::ref_map_with_index. - lift
- Dispatch for
Lift::lift2throughexplicit::lift5, and their by-reference counterpartsRefLift::ref_lift2etc. - semimonad
- Dispatch for semimonad operations:
SemimonadandRefSemimonad. - traversable
- Dispatch for
Traversable::traverseandRefTraversable::ref_traverse. - traversable_
with_ index - Dispatch for
TraversableWithIndex::traverse_with_indexandRefTraversableWithIndex::ref_traverse_with_index. - witherable
- Dispatch for witherable operations:
WitherableandRefWitherable.
Structs§
- Ref
- Marker type indicating the closure receives references.
- Val
- Marker type indicating the closure receives owned values.
Traits§
- Closure
Mode - Trait that maps a closure mode marker (
ValorRef) to the correspondingdyn Fntrait object type.