Skip to main content

send_ref_bind

Function send_ref_bind 

Source
pub fn send_ref_bind<'a, Brand: SendRefSemimonad, A: Send + Sync + 'a, B: Send + Sync + 'a>(
    ma: &<Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
    f: impl Fn(&A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B> + Send + 'a,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>
Expand description

Sequences a thread-safe computation using a reference to the value.

Free function version that dispatches to the type class’ associated function.

§Type Signature

forall Brand A B. SendRefSemimonad Brand => (&Brand A, &A -> Brand B) -> Brand B

§Type Parameters

  • 'a: The lifetime of the values.
  • Brand: The brand of the context.
  • A: The type of the value inside the context.
  • B: The type of the value in the resulting context.

§Parameters

  • ma: The context containing the value.
  • f: A thread-safe function that receives a reference to the value and returns a new context.

§Returns

A new context produced by the function.

§Examples

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

let lazy = ArcLazy::new(|| 5);
let result = send_ref_bind::<LazyBrand<ArcLazyConfig>, _, _>(&lazy, |x: &i32| {
	let v = *x * 2;
	ArcLazy::new(move || v)
});
assert_eq!(*result.evaluate(), 10);