pub struct TryThunkWithOkBrand<A>(/* private fields */);Trait Implementations§
Source§impl<A: 'static> ApplyFirst for TryThunkWithOkBrand<A>
impl<A: 'static> ApplyFirst for TryThunkWithOkBrand<A>
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<A: 'static> ApplySecond for TryThunkWithOkBrand<A>
impl<A: 'static> ApplySecond for TryThunkWithOkBrand<A>
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<A: Clone> Clone for TryThunkWithOkBrand<A>
impl<A: Clone> Clone for TryThunkWithOkBrand<A>
Source§fn clone(&self) -> TryThunkWithOkBrand<A>
fn clone(&self) -> TryThunkWithOkBrand<A>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<A: Debug> Debug for TryThunkWithOkBrand<A>
impl<A: Debug> Debug for TryThunkWithOkBrand<A>
Source§impl<A: Default> Default for TryThunkWithOkBrand<A>
impl<A: Default> Default for TryThunkWithOkBrand<A>
Source§fn default() -> TryThunkWithOkBrand<A>
fn default() -> TryThunkWithOkBrand<A>
Source§impl<A: 'static> Foldable for TryThunkWithOkBrand<A>
impl<A: 'static> Foldable for TryThunkWithOkBrand<A>
Source§fn fold_right<'a, FnBrand, E: 'a, B: 'a, Func>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>,
) -> Bwhere
Func: Fn(E, B) -> B + 'a,
FnBrand: CloneableFn + 'a,
fn fold_right<'a, FnBrand, E: 'a, B: 'a, Func>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>,
) -> Bwhere
Func: Fn(E, B) -> B + 'a,
FnBrand: CloneableFn + 'a,
Folds the TryThunk from the right (over error).
§Type Signature
forall self e b. Foldable self => ((e, b) -> b, b, self e) -> b
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.E: 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: TheTryThunkto fold.
§Returns
The final accumulator value.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let try_thunk: TryThunk<i32, i32> = pure::<TryThunkWithOkBrand<i32>, _>(10);
let result = fold_right::<RcFnBrand, TryThunkWithOkBrand<i32>, _, _, _>(|a, b| a + b, 5, try_thunk);
assert_eq!(result, 15);Source§fn fold_left<'a, FnBrand, E: 'a, B: 'a, Func>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>,
) -> Bwhere
Func: Fn(B, E) -> B + 'a,
FnBrand: CloneableFn + 'a,
fn fold_left<'a, FnBrand, E: 'a, B: 'a, Func>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>,
) -> Bwhere
Func: Fn(B, E) -> B + 'a,
FnBrand: CloneableFn + 'a,
Folds the TryThunk from the left (over error).
§Type Signature
forall self e b. Foldable self => ((b, e) -> b, b, self e) -> b
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.E: 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: TheTryThunkto fold.
§Returns
The final accumulator value.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let try_thunk: TryThunk<i32, i32> = pure::<TryThunkWithOkBrand<i32>, _>(10);
let result = fold_left::<RcFnBrand, TryThunkWithOkBrand<i32>, _, _, _>(|b, a| b + a, 5, try_thunk);
assert_eq!(result, 15);Source§fn fold_map<'a, FnBrand, E: 'a, M, Func>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>,
) -> M
fn fold_map<'a, FnBrand, E: 'a, M, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, ) -> M
Maps the value to a monoid and returns it (over error).
§Type Signature
forall self e m. (Foldable self, Monoid m) => (e -> m, self e) -> m
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function to use.E: 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::*, types::*};
let try_thunk: TryThunk<i32, i32> = pure::<TryThunkWithOkBrand<i32>, _>(10);
let result = fold_map::<RcFnBrand, TryThunkWithOkBrand<i32>, _, _, _>(|a| a.to_string(), try_thunk);
assert_eq!(result, "10");Source§impl<A: 'static> Functor for TryThunkWithOkBrand<A>
impl<A: 'static> Functor for TryThunkWithOkBrand<A>
Source§fn map<'a, E: 'a, E2: 'a, Func>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2>where
Func: Fn(E) -> E2 + 'a,
fn map<'a, E: 'a, E2: 'a, Func>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2>where
Func: Fn(E) -> E2 + 'a,
Maps a function over the error value in the TryThunk.
§Type Signature
forall self e e2. Functor self => (e -> e2, self e) -> self e2
§Type Parameters
'a: The lifetime of the computation.E: The type of the error value inside theTryThunk.E2: The type of the result of the transformation.Func: The type of the transformation function.
§Parameters
func: The function to apply to the error.fa: TheTryThunkinstance.
§Returns
A new TryThunk instance with the transformed error.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let try_thunk: TryThunk<i32, i32> = pure::<TryThunkWithOkBrand<i32>, _>(10);
let mapped = map::<TryThunkWithOkBrand<i32>, _, _, _>(|x| x * 2, try_thunk);
assert_eq!(mapped.evaluate(), Err(20));Source§impl<A: Hash> Hash for TryThunkWithOkBrand<A>
impl<A: Hash> Hash for TryThunkWithOkBrand<A>
Source§impl<A: 'static> Kind_cdc7cd43dac7585f for TryThunkWithOkBrand<A>
Generated implementation of Kind_cdc7cd43dac7585f for TryThunkWithOkBrand < A >.
impl<A: 'static> Kind_cdc7cd43dac7585f for TryThunkWithOkBrand<A>
Generated implementation of Kind_cdc7cd43dac7585f for TryThunkWithOkBrand < A >.
Source§impl<A: 'static> Lift for TryThunkWithOkBrand<A>
impl<A: 'static> Lift for TryThunkWithOkBrand<A>
Source§fn lift2<'a, E1, E2, E3, Func>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E1>,
fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E3>
fn lift2<'a, E1, E2, E3, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E1>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E3>
Lifts a binary function into the TryThunk context (over error).
§Type Signature
forall self e1 e2 e3. Lift self => ((e1, e2) -> e3, self e1, self e2) -> self e3
§Type Parameters
'a: The lifetime of the computation.E1: The type of the first error value.E2: The type of the second error value.E3: The type of the result error value.Func: The type of the binary function.
§Parameters
func: The binary function to apply to the errors.fa: The firstTryThunk.fb: The secondTryThunk.
§Returns
A new TryThunk instance containing the result of applying the function to the errors.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let eval1: TryThunk<i32, i32> = pure::<TryThunkWithOkBrand<i32>, _>(10);
let eval2: TryThunk<i32, i32> = pure::<TryThunkWithOkBrand<i32>, _>(20);
let result = lift2::<TryThunkWithOkBrand<i32>, _, _, _, _>(|a, b| a + b, eval1, eval2);
assert_eq!(result.evaluate(), Err(30));Source§impl<A: Ord> Ord for TryThunkWithOkBrand<A>
impl<A: Ord> Ord for TryThunkWithOkBrand<A>
Source§fn cmp(&self, other: &TryThunkWithOkBrand<A>) -> Ordering
fn cmp(&self, other: &TryThunkWithOkBrand<A>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<A: PartialEq> PartialEq for TryThunkWithOkBrand<A>
impl<A: PartialEq> PartialEq for TryThunkWithOkBrand<A>
Source§impl<A: PartialOrd> PartialOrd for TryThunkWithOkBrand<A>
impl<A: PartialOrd> PartialOrd for TryThunkWithOkBrand<A>
Source§impl<A: 'static> Pointed for TryThunkWithOkBrand<A>
impl<A: 'static> Pointed for TryThunkWithOkBrand<A>
Source§fn pure<'a, E: 'a>(e: E) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>
fn pure<'a, E: 'a>(e: E) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>
Wraps a value in a TryThunk context (as error).
§Type Signature
forall self e. Pointed self => e -> self e
§Type Parameters
'a: The lifetime of the computation.E: The type of the value to wrap.
§Parameters
e: The value to wrap.
§Returns
A new TryThunk instance containing the value as an error.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let try_thunk: TryThunk<i32, i32> = pure::<TryThunkWithOkBrand<i32>, _>(42);
assert_eq!(try_thunk.evaluate(), Err(42));Source§impl<A: 'static> Semiapplicative for TryThunkWithOkBrand<A>
impl<A: 'static> Semiapplicative for TryThunkWithOkBrand<A>
Source§fn apply<'a, FnBrand: 'a + CloneableFn, E1: 'a + Clone, E2: 'a>(
ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as CloneableFn>::Of<'a, E1, E2>>,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E1>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2>
fn apply<'a, FnBrand: 'a + CloneableFn, E1: 'a + Clone, E2: 'a>( ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as CloneableFn>::Of<'a, E1, E2>>, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E1>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2>
Applies a function wrapped in TryThunk (as error) to a value wrapped in TryThunk (as error).
§Type Signature
forall self e1 e2. Semiapplicative self => (self (e1 -> e2), self e1) -> self e2
§Type Parameters
'a: The lifetime of the computation.FnBrand: The brand of the cloneable function wrapper.E1: The type of the input error.E2: The type of the result error.
§Parameters
ff: TheTryThunkcontaining the function (in Err).fa: TheTryThunkcontaining the value (in Err).
§Returns
A new TryThunk instance containing the result of applying the function.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let func: TryThunk<i32, _> = pure::<TryThunkWithOkBrand<i32>, _>(cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2));
let val: TryThunk<i32, _> = pure::<TryThunkWithOkBrand<i32>, _>(21);
let result = apply::<RcFnBrand, TryThunkWithOkBrand<i32>, _, _>(func, val);
assert_eq!(result.evaluate(), Err(42));Source§impl<A: 'static> Semimonad for TryThunkWithOkBrand<A>
impl<A: 'static> Semimonad for TryThunkWithOkBrand<A>
Source§fn bind<'a, E1: 'a, E2: 'a, Func>(
ma: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E1>,
func: Func,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2>
fn bind<'a, E1: 'a, E2: 'a, Func>( ma: <Self as Kind_cdc7cd43dac7585f>::Of<'a, E1>, func: Func, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2>
Chains TryThunk computations (over error).
§Type Signature
forall self e1 e2. Semimonad self => (self e1, e1 -> self e2) -> self e2
§Type Parameters
'a: The lifetime of the computation.E1: The type of the result of the first computation (error).E2: The type of the result of the new computation (error).Func: The type of the function to apply.
§Parameters
ma: The firstTryThunk.func: The function to apply to the error result of the computation.
§Returns
A new TryThunk instance representing the chained computation.
§Examples
use fp_library::{brands::*, functions::*, types::*};
let try_thunk: TryThunk<i32, i32> = pure::<TryThunkWithOkBrand<i32>, _>(10);
let result = bind::<TryThunkWithOkBrand<i32>, _, _, _>(try_thunk, |x| pure::<TryThunkWithOkBrand<i32>, _>(x * 2));
assert_eq!(result.evaluate(), Err(20));impl<A: Copy> Copy for TryThunkWithOkBrand<A>
impl<A: Eq> Eq for TryThunkWithOkBrand<A>
impl<A> StructuralPartialEq for TryThunkWithOkBrand<A>
Auto Trait Implementations§
impl<A> Freeze for TryThunkWithOkBrand<A>
impl<A> RefUnwindSafe for TryThunkWithOkBrand<A>where
A: RefUnwindSafe,
impl<A> Send for TryThunkWithOkBrand<A>where
A: Send,
impl<A> Sync for TryThunkWithOkBrand<A>where
A: Sync,
impl<A> Unpin for TryThunkWithOkBrand<A>where
A: Unpin,
impl<A> UnwindSafe for TryThunkWithOkBrand<A>where
A: UnwindSafe,
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