Defer

Trait Defer 

Source
pub trait Defer<'a> {
    // Required method
    fn defer<ClonableFnBrand: 'a + ClonableFn>(
        f: ApplyClonableFn<'a, ClonableFnBrand, (), Self>,
    ) -> Self
       where Self: Sized;
}
Expand description

A type class for types that can be constructed lazily.

Required Methods§

Source

fn defer<ClonableFnBrand: 'a + ClonableFn>( f: ApplyClonableFn<'a, ClonableFnBrand, (), Self>, ) -> Self
where Self: Sized,

Creates a value from a computation that produces the value.

§Type Signature

forall a. Defer d => (() -> d a) -> d a

§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);

Implementors§

Source§

impl<'a, OnceBrand: Once + 'a, CFB: ClonableFn + 'a, A: Clone + 'a> Defer<'a> for Lazy<'a, OnceBrand, CFB, A>