pub trait Extract: Kind_cdc7cd43dac7585f {
// Required method
fn extract<'a, A: 'a>(fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>) -> A;
}Expand description
A type containing exactly one extractable value, providing a natural
transformation F ~> Id.
This trait witnesses that a type always holds a single value that can be
extracted by running its effect. It is used by
Free::evaluate to execute the effects in a
Free monad.
Extract is the inverse of Deferrable:
Deferrable constructs lazy values from thunks, while Extract forces and
extracts them. For types whose brand implements Extract (e.g.,
ThunkBrand), the round-trip law extract(defer(|| x)) == x holds.
Implemented by types that always contain exactly one value and can
surrender ownership of it. Lazy cannot implement
this trait because forcing it returns &A (a reference), not an owned A.
Trampoline does not have a brand and therefore
cannot participate in HKT traits.
§Laws
Pure-extract: extracting a pure value returns the original value.
For any x: A:
extract(pure(x)) == xThis law states that wrapping a value in the type and immediately extracting it is the identity.
Required Methods§
Sourcefn extract<'a, A: 'a>(fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>) -> A
fn extract<'a, A: 'a>(fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>) -> A
Extracts the inner value.
§Type Signature
forall A. Self A -> A
§Type Parameters
'a: The lifetime of the value.A: The type of the value inside the container.
§Parameters
fa: The container to extract from.
§Returns
The inner value.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let thunk = Thunk::new(|| 42);
assert_eq!(extract::<ThunkBrand, _>(thunk), 42);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.