Skip to main content

Module ref_semimonad

Module ref_semimonad 

Source
Expand description

Contexts supporting by-reference monadic sequencing via bind.

Like Semimonad::bind, but the closure receives &A instead of A. This enables memoized types like Lazy to participate in monadic sequencing without giving up their cached value.

§Examples

use fp_library::{
	brands::*,
	classes::*,
	types::*,
};

let lazy = RcLazy::pure(5);
let result = LazyBrand::<RcLazyConfig>::ref_bind(&lazy, |x: &i32| {
	Lazy::<_, RcLazyConfig>::new({
		let v = *x;
		move || v * 2
	})
});
assert_eq!(*result.evaluate(), 10);

Traits§

RefSemimonad
A type class for contexts supporting by-reference monadic sequencing.

Functions§

ref_join
Like ref_bind, but with the arguments flipped. Collapses two nested layers of a by-ref semimonad into one.