pub trait Deferrable<'a> {
// Required method
fn defer<F>(f: F) -> Self
where F: FnOnce() -> Self + 'a,
Self: Sized;
}Expand description
A type class for types that can be constructed lazily.
Required Methods§
Sourcefn defer<F>(f: F) -> Self
fn defer<F>(f: F) -> Self
Creates a value from a computation that produces the value.
This function takes a thunk and creates a deferred value that will be computed using the thunk.
§Type Signature
forall self. Deferrable self => (() -> self) -> self
§Type Parameters
F: The type of the thunk.
§Parameters
f: A thunk that produces the value.
§Returns
The deferred value.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let eval: Thunk<i32> = defer(|| Thunk::new(|| 42));
assert_eq!(eval.evaluate(), 42);