pub struct ThunkBrand;Expand description
Brand for Thunk.
Note: This is for Thunk<'a, A>, NOT for Trampoline<A>.
Trampoline cannot implement HKT traits due to its 'static requirement.
Trait Implementations§
Source§impl ApplyFirst for ThunkBrand
impl ApplyFirst for ThunkBrand
Source§fn apply_first<'a, A: 'a + Clone, B: 'a + Clone>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn apply_first<'a, A: 'a + Clone, B: 'a + Clone>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Source§impl ApplySecond for ThunkBrand
impl ApplySecond for ThunkBrand
Source§fn apply_second<'a, A: 'a + Clone, B: 'a + Clone>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn apply_second<'a, A: 'a + Clone, B: 'a + Clone>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Source§impl Clone for ThunkBrand
impl Clone for ThunkBrand
Source§fn clone(&self) -> ThunkBrand
fn clone(&self) -> ThunkBrand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ThunkBrand
impl Debug for ThunkBrand
Source§impl Default for ThunkBrand
impl Default for ThunkBrand
Source§fn default() -> ThunkBrand
fn default() -> ThunkBrand
Source§impl Evaluable for ThunkBrand
impl Evaluable for ThunkBrand
Source§fn evaluate<'a, A: 'a>(fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>) -> A
fn evaluate<'a, A: 'a>(fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>) -> A
Runs the eval, producing the inner value.
§Type Signature
forall self a. Evaluable self => self a -> a
§Type Parameters
'a: The lifetime of the computation.A: The type of the value inside the thunk.
§Parameters
fa: The eval to run.
§Returns
The result of running the thunk.
§Examples
use fp_library::{brands::*, classes::*, functions::*, types::*};
let thunk = Thunk::new(|| 42);
assert_eq!(evaluate::<ThunkBrand, _>(thunk), 42);Source§impl Foldable for ThunkBrand
impl Foldable for ThunkBrand
Source§fn fold_right<'a, FnBrand, A: 'a, B: 'a, Func>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
Func: Fn(A, B) -> B + 'a,
FnBrand: CloneableFn + 'a,
fn fold_right<'a, FnBrand, A: 'a, B: 'a, Func>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
Func: Fn(A, B) -> B + 'a,
FnBrand: CloneableFn + 'a,
Folds the Thunk from the right.
§Type Signature
forall self a b. Foldable self => ((a, b) -> b, b, self a) -> b
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.A: The type of the elements in the structure.B: The type of the accumulator.Func: The type of the folding function.
§Parameters
func: The function to apply to each element and the accumulator.initial: The initial value of the accumulator.fa: TheThunkto fold.
§Returns
The final accumulator value.
§Examples
use fp_library::{brands::*, functions::*};
let thunk = pure::<ThunkBrand, _>(10);
let result = fold_right::<RcFnBrand, ThunkBrand, _, _, _>(|a, b| a + b, 5, thunk);
assert_eq!(result, 15);Source§fn fold_left<'a, FnBrand, A: 'a, B: 'a, Func>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
Func: Fn(B, A) -> B + 'a,
FnBrand: CloneableFn + 'a,
fn fold_left<'a, FnBrand, A: 'a, B: 'a, Func>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
Func: Fn(B, A) -> B + 'a,
FnBrand: CloneableFn + 'a,
Folds the Thunk from the left.
§Type Signature
forall self a b. Foldable self => ((b, a) -> b, b, self a) -> b
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.A: The type of the elements in the structure.B: The type of the accumulator.Func: The type of the folding function.
§Parameters
func: The function to apply to the accumulator and each element.initial: The initial value of the accumulator.fa: TheThunkto fold.
§Returns
The final accumulator value.
§Examples
use fp_library::{brands::*, functions::*};
let thunk = pure::<ThunkBrand, _>(10);
let result = fold_left::<RcFnBrand, ThunkBrand, _, _, _>(|b, a| b + a, 5, thunk);
assert_eq!(result, 15);Source§fn fold_map<'a, FnBrand, A: 'a, M, Func>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> M
fn fold_map<'a, FnBrand, A: 'a, M, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
Maps the value to a monoid and returns it.
§Type Signature
forall self a m. (Foldable self, Monoid m) => (a -> m, self a) -> m
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.A: The type of the elements in the structure.M: The type of the monoid.Func: The type of the mapping function.
§Parameters
func: The mapping function.fa: The Thunk to fold.
§Returns
The monoid value.
§Examples
use fp_library::{brands::*, functions::*};
let thunk = pure::<ThunkBrand, _>(10);
let result = fold_map::<RcFnBrand, ThunkBrand, _, _, _>(|a| a.to_string(), thunk);
assert_eq!(result, "10");Source§impl Functor for ThunkBrand
impl Functor for ThunkBrand
Source§fn map<'a, A: 'a, B: 'a, Func>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>where
Func: Fn(A) -> B + 'a,
fn map<'a, A: 'a, B: 'a, Func>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>where
Func: Fn(A) -> B + 'a,
Maps a function over the result of a Thunk computation.
§Type Signature
forall self a b. Functor self => (a -> b, self a) -> self b
§Type Parameters
'a: The lifetime of the computation.A: The type of the value inside theThunk.B: The type of the result of the transformation.Func: The type of the transformation function.
§Parameters
func: The function to apply to the result of the computation.fa: TheThunkinstance.
§Returns
A new Thunk instance with the transformed result.
§Examples
use fp_library::{brands::*, functions::*};
let thunk = pure::<ThunkBrand, _>(10);
let mapped = map::<ThunkBrand, _, _, _>(|x| x * 2, thunk);
assert_eq!(mapped.evaluate(), 20);Source§impl Hash for ThunkBrand
impl Hash for ThunkBrand
Source§impl Kind_cdc7cd43dac7585f for ThunkBrand
Generated implementation of Kind_cdc7cd43dac7585f for ThunkBrand.
impl Kind_cdc7cd43dac7585f for ThunkBrand
Generated implementation of Kind_cdc7cd43dac7585f for ThunkBrand.
Source§impl Lift for ThunkBrand
impl Lift for ThunkBrand
Source§fn lift2<'a, A, B, C, Func>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, C>
fn lift2<'a, A, B, C, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, C>
Lifts a binary function into the Thunk context.
§Type Signature
forall self a b c. Lift self => ((a, b) -> c, self a, self b) -> self c
§Type Parameters
'a: The lifetime of the computation.A: The type of the first value.B: The type of the second value.C: The type of the result.Func: The type of the binary function.
§Parameters
func: The binary function to apply.fa: The firstThunk.fb: The secondThunk.
§Returns
A new Thunk instance containing the result of applying the function.
§Examples
use fp_library::{brands::*, functions::*};
let eval1 = pure::<ThunkBrand, _>(10);
let eval2 = pure::<ThunkBrand, _>(20);
let result = lift2::<ThunkBrand, _, _, _, _>(|a, b| a + b, eval1, eval2);
assert_eq!(result.evaluate(), 30);Source§impl MonadRec for ThunkBrand
impl MonadRec for ThunkBrand
Source§fn tail_rec_m<'a, A: 'a, B: 'a, F>(
f: F,
a: A,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn tail_rec_m<'a, A: 'a, B: 'a, F>( f: F, a: A, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Performs tail-recursive monadic computation.
§Type Signature
forall self a b. MonadRec self => (a -> self (Step a b), a) -> self b
§Type Parameters
'a: The lifetime of the computation.A: The type of the initial value and loop state.B: The type of the result.F: The type of the step function.
§Parameters
f: The step function.a: The initial value.
§Returns
The result of the computation.
§Examples
use fp_library::{brands::*, classes::*, functions::*, types::*};
let result = tail_rec_m::<ThunkBrand, _, _, _>(
|x| pure::<ThunkBrand, _>(if x < 1000 { Step::Loop(x + 1) } else { Step::Done(x) }),
0,
);
assert_eq!(result.evaluate(), 1000);Source§impl Ord for ThunkBrand
impl Ord for ThunkBrand
Source§fn cmp(&self, other: &ThunkBrand) -> Ordering
fn cmp(&self, other: &ThunkBrand) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ThunkBrand
impl PartialEq for ThunkBrand
Source§impl PartialOrd for ThunkBrand
impl PartialOrd for ThunkBrand
Source§impl Pointed for ThunkBrand
impl Pointed for ThunkBrand
Source§fn pure<'a, A: 'a>(a: A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn pure<'a, A: 'a>(a: A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Wraps a value in a Thunk context.
§Type Signature
forall self a. Pointed self => a -> self a
§Type Parameters
'a: The lifetime of the computation.A: The type of the value to wrap.
§Parameters
a: The value to wrap.
§Returns
A new Thunk instance containing the value.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let thunk: Thunk<i32> = pure::<ThunkBrand, _>(42);
assert_eq!(thunk.evaluate(), 42);Source§impl Semiapplicative for ThunkBrand
impl Semiapplicative for ThunkBrand
Source§fn apply<'a, FnBrand: 'a + CloneableFn, A: 'a + Clone, B: 'a>(
ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as CloneableFn>::Of<'a, A, B>>,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn apply<'a, FnBrand: 'a + CloneableFn, A: 'a + Clone, B: 'a>( ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as CloneableFn>::Of<'a, A, B>>, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Applies a function wrapped in Thunk to a value wrapped in Thunk.
§Type Signature
forall self a b. Semiapplicative self => (self (a -> b), self a) -> self b
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function wrapper.A: The type of the input.B: The type of the result.
§Parameters
ff: TheThunkcontaining the function.fa: TheThunkcontaining the value.
§Returns
A new Thunk instance containing the result of applying the function.
§Examples
use fp_library::{brands::*, functions::*};
let func = pure::<ThunkBrand, _>(cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2));
let val = pure::<ThunkBrand, _>(21);
let result = apply::<RcFnBrand, ThunkBrand, _, _>(func, val);
assert_eq!(result.evaluate(), 42);Source§impl Semimonad for ThunkBrand
impl Semimonad for ThunkBrand
Source§fn bind<'a, A: 'a, B: 'a, Func>(
ma: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
func: Func,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn bind<'a, A: 'a, B: 'a, Func>( ma: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, func: Func, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Chains Thunk computations.
§Type Signature
forall self a b. Semimonad self => (self a, a -> self b) -> self b
§Type Parameters
'a: The lifetime of the computation.A: The type of the result of the first computation.B: The type of the result of the new computation.Func: The type of the function to apply.
§Parameters
ma: The firstThunk.func: The function to apply to the result of the computation.
§Returns
A new Thunk instance representing the chained computation.
§Examples
use fp_library::{brands::*, functions::*};
let thunk = pure::<ThunkBrand, _>(10);
let result = bind::<ThunkBrand, _, _, _>(thunk, |x| pure::<ThunkBrand, _>(x * 2));
assert_eq!(result.evaluate(), 20);impl Copy for ThunkBrand
impl Eq for ThunkBrand
impl StructuralPartialEq for ThunkBrand
Auto Trait Implementations§
impl Freeze for ThunkBrand
impl RefUnwindSafe for ThunkBrand
impl Send for ThunkBrand
impl Sync for ThunkBrand
impl Unpin for ThunkBrand
impl UnwindSafe for ThunkBrand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more