Expand description
By-ref monads, combining RefApplicative and RefSemimonad.
This is the by-ref counterpart of Monad.
Enables monadic sequencing where the continuation receives &A instead
of owned A, and value injection clones from &A.
§Examples
use fp_library::{
brands::*,
classes::*,
functions::{
explicit::bind,
*,
},
types::*,
};
// Chain computations on memoized values by reference
let lazy = ref_pure::<LazyBrand<RcLazyConfig>, _>(&5);
let result = bind::<LazyBrand<RcLazyConfig>, _, _, _, _>(&lazy, |x: &i32| {
let v = *x * 2;
ref_pure::<LazyBrand<RcLazyConfig>, _>(&v)
});
assert_eq!(*result.evaluate(), 10);Traits§
- RefMonad
- A type class for by-ref monads.
Functions§
- ref_
if_ m - Executes a monadic action conditionally, using by-ref bind.
- ref_
unless_ m - Performs a monadic action when a by-ref condition is false.