pub struct OptionBrand;Trait Implementations§
Source§impl ApplyFirst for OptionBrand
impl ApplyFirst for OptionBrand
Source§impl ApplySecond for OptionBrand
impl ApplySecond for OptionBrand
Source§impl Clone for OptionBrand
impl Clone for OptionBrand
Source§fn clone(&self) -> OptionBrand
fn clone(&self) -> OptionBrand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OptionBrand
impl Debug for OptionBrand
Source§impl Default for OptionBrand
impl Default for OptionBrand
Source§fn default() -> OptionBrand
fn default() -> OptionBrand
Source§impl Foldable for OptionBrand
impl Foldable for OptionBrand
Source§fn fold_right<'a, A: 'a, B: 'a, F>(
f: F,
init: B,
fa: Apply1L1T<'a, Self, A>,
) -> Bwhere
F: Fn(A, B) -> B + 'a,
fn fold_right<'a, A: 'a, B: 'a, F>(
f: F,
init: B,
fa: Apply1L1T<'a, Self, A>,
) -> Bwhere
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: Apply1L1T<'a, Self, A>,
) -> Bwhere
F: Fn(B, A) -> B + 'a,
fn fold_left<'a, A: 'a, B: 'a, F>(
f: F,
init: B,
fa: Apply1L1T<'a, Self, A>,
) -> Bwhere
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: Apply1L1T<'a, Self, A>) -> M
fn fold_map<'a, A: 'a, M, F>(f: F, fa: Apply1L1T<'a, Self, A>) -> M
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
impl Functor for OptionBrand
Source§fn map<'a, A: 'a, B: 'a, F>(
f: F,
fa: Apply1L1T<'a, Self, A>,
) -> Apply1L1T<'a, Self, B>where
F: Fn(A) -> B + 'a,
fn map<'a, A: 'a, B: 'a, F>(
f: F,
fa: Apply1L1T<'a, Self, A>,
) -> Apply1L1T<'a, Self, 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
impl Hash for OptionBrand
Source§impl Lift for OptionBrand
impl Lift for OptionBrand
Source§fn lift2<'a, A, B, C, F>(
f: F,
fa: Apply1L1T<'a, Self, A>,
fb: Apply1L1T<'a, Self, B>,
) -> Apply1L1T<'a, Self, C>where
F: Fn(A, B) -> C + 'a,
A: 'a,
B: 'a,
C: 'a,
fn lift2<'a, A, B, C, F>(
f: F,
fa: Apply1L1T<'a, Self, A>,
fb: Apply1L1T<'a, Self, B>,
) -> Apply1L1T<'a, Self, 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
impl Ord for OptionBrand
Source§fn cmp(&self, other: &OptionBrand) -> Ordering
fn cmp(&self, other: &OptionBrand) -> 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 OptionBrand
impl PartialEq for OptionBrand
Source§impl PartialOrd for OptionBrand
impl PartialOrd for OptionBrand
Source§impl Semiapplicative for OptionBrand
impl Semiapplicative for OptionBrand
Source§fn apply<'a, A: 'a + Clone, B: 'a, FnBrand: 'a + ClonableFn>(
ff: Apply1L1T<'a, Self, ApplyClonableFn<'a, FnBrand, A, B>>,
fa: Apply1L1T<'a, Self, A>,
) -> Apply1L1T<'a, Self, B>
fn apply<'a, A: 'a + Clone, B: 'a, FnBrand: 'a + ClonableFn>( ff: Apply1L1T<'a, Self, ApplyClonableFn<'a, FnBrand, A, B>>, fa: Apply1L1T<'a, Self, A>, ) -> Apply1L1T<'a, Self, 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
impl Semimonad for OptionBrand
Source§fn bind<'a, A: 'a, B: 'a, F>(
ma: Apply1L1T<'a, Self, A>,
f: F,
) -> Apply1L1T<'a, Self, B>
fn bind<'a, A: 'a, B: 'a, F>( ma: Apply1L1T<'a, Self, A>, f: F, ) -> Apply1L1T<'a, Self, B>
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
impl Traversable for OptionBrand
Source§fn traverse<'a, F: Applicative, A: 'a + Clone, B: 'a + Clone, Func>(
f: Func,
ta: Apply1L1T<'a, Self, A>,
) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, B>>
fn traverse<'a, F: Applicative, A: 'a + Clone, B: 'a + Clone, Func>( f: Func, ta: Apply1L1T<'a, Self, A>, ) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, B>>
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: Apply1L1T<'a, Self, Apply1L1T<'a, F, A>>,
) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, A>>
fn sequence<'a, F: Applicative, A: 'a + Clone>( ta: Apply1L1T<'a, Self, Apply1L1T<'a, F, A>>, ) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, A>>
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)));