pub trait Defer<'a> {
// Required method
fn defer<FnBrand: 'a + ClonableFn>(
f: <FnBrand as ClonableFn>::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 + ClonableFn>(
f: <FnBrand as ClonableFn>::Of<'a, (), Self>,
) -> Selfwhere
Self: Sized,
fn defer<FnBrand: 'a + ClonableFn>(
f: <FnBrand as ClonableFn>::Of<'a, (), Self>,
) -> Selfwhere
Self: Sized,
Creates a value from a computation that produces the value.
This function takes a thunk (wrapped in a clonable 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 clonable function wrapper.
§Parameters
f: A thunk (wrapped in a clonable function) that produces the value.
§Returns
The deferred value.
§Examples
use fp_library::classes::defer::Defer;
use fp_library::types::lazy::Lazy;
use fp_library::brands::RcFnBrand;
use fp_library::brands::OnceCellBrand;
use fp_library::classes::clonable_fn::ClonableFn;
let lazy = Lazy::<OnceCellBrand, RcFnBrand, _>::defer::<RcFnBrand>(
<RcFnBrand as ClonableFn>::new(|_| Lazy::new(<RcFnBrand as ClonableFn>::new(|_| 42)))
);
assert_eq!(Lazy::force(lazy), 42);