pub trait Defer<'a> {
// Required method
fn defer<FnBrand: 'a + CloneableFn>(
f: <FnBrand as CloneableFn>::Of<'a, (), Self>,
) -> Self
where Self: Sized;
}Expand description
A type class for types that can be constructed lazily.
Required Methods§
Sourcefn defer<FnBrand: 'a + CloneableFn>(
f: <FnBrand as CloneableFn>::Of<'a, (), Self>,
) -> Selfwhere
Self: Sized,
fn defer<FnBrand: 'a + CloneableFn>(
f: <FnBrand as CloneableFn>::Of<'a, (), Self>,
) -> Selfwhere
Self: Sized,
Creates a value from a computation that produces the value.
This function takes a thunk (wrapped in a cloneable function) and creates a deferred value that will be computed using the thunk.
§Type Signature
forall a. Defer d => (() -> d a) -> d a
§Type Parameters
FnBrand: The brand of the cloneable function wrapper.
§Parameters
f: A thunk (wrapped in a cloneable function) that produces the value.
§Returns
The deferred value.
§Examples
use fp_library::{brands::*, classes::*, functions::*, types::*};
let eval: Thunk<i32> = defer::<Thunk<i32>, RcFnBrand>(
cloneable_fn_new::<RcFnBrand, _, _>(|_| Thunk::new(|| 42))
);
assert_eq!(eval.run(), 42);