Skip to main content

TryThunkWithOkBrand

Struct TryThunkWithOkBrand 

Source
pub struct TryThunkWithOkBrand<A>(/* private fields */);
Expand description

Brand for TryThunk with the success value filled in (Functor over Err).

Trait Implementations§

Source§

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>

Combines two contexts, keeping the value from the first context. Read more
Source§

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>

Combines two contexts, keeping the value from the second context. Read more
Source§

impl<A: Clone> Clone for TryThunkWithOkBrand<A>

Source§

fn clone(&self) -> TryThunkWithOkBrand<A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Debug> Debug for TryThunkWithOkBrand<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: Default> Default for TryThunkWithOkBrand<A>

Source§

fn default() -> TryThunkWithOkBrand<A>

Returns the “default value” for a type. Read more
Source§

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>, ) -> B
where 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: The TryThunk to 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>, ) -> B
where 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: The TryThunk to 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
where M: Monoid + 'a, Func: Fn(E) -> M + 'a, FnBrand: CloneableFn + 'a,

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>

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,

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 the TryThunk.
  • 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: The TryThunk instance.
§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>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<A: 'static> Kind_cdc7cd43dac7585f for TryThunkWithOkBrand<A>

Generated implementation of Kind_cdc7cd43dac7585f for TryThunkWithOkBrand < A >.

Source§

type Of<'a, E: 'a> = TryThunk<'a, A, E>

The applied type.
Source§

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>
where Func: Fn(E1, E2) -> E3 + 'a, E1: Clone + 'a, E2: Clone + 'a, E3: 'a,

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 first TryThunk.
  • fb: The second TryThunk.
§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>

Source§

fn cmp(&self, other: &TryThunkWithOkBrand<A>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<A: PartialEq> PartialEq for TryThunkWithOkBrand<A>

Source§

fn eq(&self, other: &TryThunkWithOkBrand<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: PartialOrd> PartialOrd for TryThunkWithOkBrand<A>

Source§

fn partial_cmp(&self, other: &TryThunkWithOkBrand<A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<A: 'static> Pointed for TryThunkWithOkBrand<A>

Source§

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>

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>

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: The TryThunk containing the function (in Err).
  • fa: The TryThunk containing 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>

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>
where Func: Fn(E1) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, E2> + 'a,

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 first TryThunk.
  • 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));
Source§

impl<A: Copy> Copy for TryThunkWithOkBrand<A>

Source§

impl<A: Eq> Eq for TryThunkWithOkBrand<A>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<Brand> Applicative for Brand

Source§

impl<Brand> Monad for Brand
where Brand: Applicative + Semimonad,