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
(() -> 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);Implementors§
impl<'a, A> Deferrable<'a> for Lazy<'a, A, RcLazyConfig>where
A: Clone + 'a,
§Type Parameters
'a: The lifetime of the reference.A: The type of the computed value.
impl<'a, A, E> Deferrable<'a> for TryLazy<'a, A, E, RcLazyConfig>
§Type Parameters
'a: The lifetime of the computation.A: The type of the computed value.E: The type of the error.
impl<'a, A, E> Deferrable<'a> for TryThunk<'a, A, E>where
A: 'a,
E: 'a,
§Type Parameters
'a: The lifetime of the computation.A: The type of the success value.E: The type of the error value.
impl<'a, A: 'a> Deferrable<'a> for Thunk<'a, A>
§Type Parameters
'a: The lifetime of the computation.A: The type of the value produced by the computation.
impl<A, E> Deferrable<'static> for TryTrampoline<A, E>
§Type Parameters
A: The type of the success value.E: The type of the error value.
impl<A: 'static + Send> Deferrable<'static> for Trampoline<A>
§Type Parameters
A: The type of the value produced by the task.
impl<A: 'static> Deferrable<'static> for Free<ThunkBrand, A>
A: The result type.