OptionBrand

Struct OptionBrand 

Source
pub struct OptionBrand;
Expand description

Trait Implementations§

Source§

impl ApplyFirst for OptionBrand

Source§

fn apply_first<'a, A: 'a + Clone, B: 'a + Clone>( fa: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, fb: <Self as Kind_c3c3610c70409ee6>::Of<'a, B>, ) -> <Self as Kind_c3c3610c70409ee6>::Of<'a, A>

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

impl ApplySecond for OptionBrand

Source§

fn apply_second<'a, A: 'a + Clone, B: 'a + Clone>( fa: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, fb: <Self as Kind_c3c3610c70409ee6>::Of<'a, B>, ) -> <Self as Kind_c3c3610c70409ee6>::Of<'a, B>

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

impl Clone for OptionBrand

Source§

fn clone(&self) -> OptionBrand

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 Debug for OptionBrand

Source§

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

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

impl Default for OptionBrand

Source§

fn default() -> OptionBrand

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

impl Foldable for OptionBrand

Source§

fn fold_right<'a, A: 'a, B: 'a, F>( f: F, init: B, fa: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, ) -> B
where F: Fn(A, B) -> B + 'a,

Folds the option from the right.

§Type Signature

forall a b. Foldable Option => ((a, b) -> b, b, Option a) -> b

§Parameters
  • f: The folding function.
  • init: The initial value.
  • fa: The option to fold.
§Returns

f(a, init) if fa is Some(a), otherwise init.

§Examples
use fp_library::classes::foldable::fold_right;
use fp_library::brands::OptionBrand;

assert_eq!(fold_right::<OptionBrand, _, _, _>(|x: i32, acc| x + acc, 0, Some(5)), 5);
assert_eq!(fold_right::<OptionBrand, _, _, _>(|x: i32, acc| x + acc, 0, None), 0);
Source§

fn fold_left<'a, A: 'a, B: 'a, F>( f: F, init: B, fa: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, ) -> B
where F: Fn(B, A) -> B + 'a,

Folds the option from the left.

§Type Signature

forall a b. Foldable Option => ((b, a) -> b, b, Option a) -> b

§Parameters
  • f: The folding function.
  • init: The initial value.
  • fa: The option to fold.
§Returns

f(init, a) if fa is Some(a), otherwise init.

§Examples
use fp_library::classes::foldable::fold_left;
use fp_library::brands::OptionBrand;

assert_eq!(fold_left::<OptionBrand, _, _, _>(|acc, x: i32| acc + x, 0, Some(5)), 5);
Source§

fn fold_map<'a, A: 'a, M, F>( f: F, fa: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, ) -> M
where M: Monoid + 'a, F: Fn(A) -> M + 'a,

Maps the value to a monoid and returns it, or returns empty.

§Type Signature

forall a m. (Foldable Option, Monoid m) => ((a) -> m, Option a) -> m

§Parameters
  • f: The mapping function.
  • fa: The option to fold.
§Returns

f(a) if fa is Some(a), otherwise M::empty().

§Examples
use fp_library::classes::foldable::fold_map;
use fp_library::brands::OptionBrand;
use fp_library::types::string; // Import to bring Monoid impl for String into scope

assert_eq!(fold_map::<OptionBrand, _, _, _>(|x: i32| x.to_string(), Some(5)), "5".to_string());
Source§

impl Functor for OptionBrand

Source§

fn map<'a, A: 'a, B: 'a, F>( f: F, fa: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, ) -> <Self as Kind_c3c3610c70409ee6>::Of<'a, B>
where F: Fn(A) -> B + 'a,

Maps a function over the value in the option.

§Type Signature

forall a b. Functor Option => (a -> b, Option a) -> Option b

§Parameters
  • f: The function to apply to the value.
  • fa: The option to map over.
§Returns

A new option containing the result of applying the function, or None.

§Examples
use fp_library::classes::functor::map;
use fp_library::brands::OptionBrand;

assert_eq!(map::<OptionBrand, _, _, _>(|x: i32| x * 2, Some(5)), Some(10));
assert_eq!(map::<OptionBrand, _, _, _>(|x: i32| x * 2, None), None);
Source§

impl Hash for OptionBrand

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 Kind_c3c3610c70409ee6 for OptionBrand

Generated implementation of Kind_c3c3610c70409ee6 for OptionBrand.

Source§

type Of<'a, A: 'a> = Option<A>

Source§

impl Lift for OptionBrand

Source§

fn lift2<'a, A, B, C, F>( f: F, fa: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, fb: <Self as Kind_c3c3610c70409ee6>::Of<'a, B>, ) -> <Self as Kind_c3c3610c70409ee6>::Of<'a, C>
where F: Fn(A, B) -> C + 'a, A: 'a, B: 'a, C: 'a,

Lifts a binary function into the option context.

§Type Signature

forall a b c. Lift Option => ((a, b) -> c, Option a, Option b) -> Option c

§Parameters
  • f: The binary function to apply.
  • fa: The first option.
  • fb: The second option.
§Returns

Some(f(a, b)) if both options are Some, otherwise None.

§Examples
use fp_library::classes::lift::lift2;
use fp_library::brands::OptionBrand;

assert_eq!(lift2::<OptionBrand, _, _, _, _>(|x: i32, y: i32| x + y, Some(1), Some(2)), Some(3));
assert_eq!(lift2::<OptionBrand, _, _, _, _>(|x: i32, y: i32| x + y, Some(1), None), None);
Source§

impl Ord for OptionBrand

Source§

fn cmp(&self, other: &OptionBrand) -> 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 PartialEq for OptionBrand

Source§

fn eq(&self, other: &OptionBrand) -> 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 PartialOrd for OptionBrand

Source§

fn partial_cmp(&self, other: &OptionBrand) -> 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 Pointed for OptionBrand

Source§

fn pure<'a, A: 'a>(a: A) -> <Self as Kind_c3c3610c70409ee6>::Of<'a, A>

Wraps a value in an option.

§Type Signature

forall a. Pointed Option => a -> Option a

§Parameters
  • a: The value to wrap.
§Returns

Some(a).

§Examples
use fp_library::classes::pointed::pure;
use fp_library::brands::OptionBrand;

assert_eq!(pure::<OptionBrand, _>(5), Some(5));
Source§

impl Semiapplicative for OptionBrand

Source§

fn apply<'a, A: 'a + Clone, B: 'a, FnBrand: 'a + ClonableFn>( ff: <Self as Kind_c3c3610c70409ee6>::Of<'a, <FnBrand as ClonableFn>::Of<'a, A, B>>, fa: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, ) -> <Self as Kind_c3c3610c70409ee6>::Of<'a, B>

Applies a wrapped function to a wrapped value.

§Type Signature

forall a b. Semiapplicative Option => (Option (a -> b), Option a) -> Option b

§Parameters
  • ff: The option containing the function.
  • fa: The option containing the value.
§Returns

Some(f(a)) if both are Some, otherwise None.

§Examples
use fp_library::classes::semiapplicative::apply;
use fp_library::classes::clonable_fn::ClonableFn;
use fp_library::brands::{OptionBrand};
use fp_library::brands::RcFnBrand;
use std::rc::Rc;

let f = Some(<RcFnBrand as ClonableFn>::new(|x: i32| x * 2));
assert_eq!(apply::<OptionBrand, _, _, RcFnBrand>(f, Some(5)), Some(10));
Source§

impl Semimonad for OptionBrand

Source§

fn bind<'a, A: 'a, B: 'a, F>( ma: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, f: F, ) -> <Self as Kind_c3c3610c70409ee6>::Of<'a, B>
where F: Fn(A) -> <Self as Kind_c3c3610c70409ee6>::Of<'a, B> + 'a,

Chains option computations.

§Type Signature

forall a b. Semimonad Option => (Option a, a -> Option b) -> Option b

§Parameters
  • ma: The first option.
  • f: The function to apply to the value inside the option.
§Returns

The result of applying f to the value if ma is Some, otherwise None.

§Examples
use fp_library::classes::semimonad::bind;
use fp_library::brands::OptionBrand;

assert_eq!(bind::<OptionBrand, _, _, _>(Some(5), |x| Some(x * 2)), Some(10));
assert_eq!(bind::<OptionBrand, _, _, _>(None, |x: i32| Some(x * 2)), None);
Source§

impl Traversable for OptionBrand

Source§

fn traverse<'a, F: Applicative, A: 'a + Clone, B: 'a + Clone, Func>( f: Func, ta: <Self as Kind_c3c3610c70409ee6>::Of<'a, A>, ) -> <F as Kind_c3c3610c70409ee6>::Of<'a, <Self as Kind_c3c3610c70409ee6>::Of<'a, B>>
where Func: Fn(A) -> <F as Kind_c3c3610c70409ee6>::Of<'a, B> + 'a, <Self as Kind_c3c3610c70409ee6>::Of<'a, B>: Clone,

Traverses the option with an applicative function.

§Type Signature

forall a b f. (Traversable Option, Applicative f) => (a -> f b, Option a) -> f (Option b)

§Parameters
  • f: The function to apply.
  • ta: The option to traverse.
§Returns

The option wrapped in the applicative context.

§Examples
use fp_library::classes::traversable::traverse;
use fp_library::brands::OptionBrand;

assert_eq!(traverse::<OptionBrand, OptionBrand, _, _, _>(|x| Some(x * 2), Some(5)), Some(Some(10)));
Source§

fn sequence<'a, F: Applicative, A: 'a + Clone>( ta: <Self as Kind_c3c3610c70409ee6>::Of<'a, <F as Kind_c3c3610c70409ee6>::Of<'a, A>>, ) -> <F as Kind_c3c3610c70409ee6>::Of<'a, <Self as Kind_c3c3610c70409ee6>::Of<'a, A>>
where <F as Kind_c3c3610c70409ee6>::Of<'a, A>: Clone, <Self as Kind_c3c3610c70409ee6>::Of<'a, A>: Clone,

Sequences an option of applicative.

§Type Signature

forall a f. (Traversable Option, Applicative f) => (Option (f a)) -> f (Option a)

§Parameters
  • ta: The option containing the applicative value.
§Returns

The option wrapped in the applicative context.

§Examples
use fp_library::classes::traversable::sequence;
use fp_library::brands::OptionBrand;

assert_eq!(sequence::<OptionBrand, OptionBrand, _>(Some(Some(5))), Some(Some(5)));
Source§

impl Copy for OptionBrand

Source§

impl Eq for OptionBrand

Source§

impl StructuralPartialEq for OptionBrand

Auto Trait Implementations§

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> 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,