pub struct OptionBrand;Expand description
Brand for Option.
Trait Implementations§
Source§impl ApplyFirst for OptionBrand
impl ApplyFirst for OptionBrand
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 OptionBrand
impl ApplySecond for OptionBrand
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 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 Compactable for OptionBrand
impl Compactable for OptionBrand
Source§fn compact<'a, A: 'a>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn compact<'a, A: 'a>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Compacts a nested option.
This method flattens a nested option.
§Type Signature
forall a. Compactable Option => Option (Option a) -> Option a
§Parameters
fa: The nested option.
§Returns
The flattened option.
§Examples
use fp_library::classes::compactable::Compactable;
use fp_library::brands::OptionBrand;
let x = Some(Some(5));
let y = OptionBrand::compact(x);
assert_eq!(y, Some(5));Source§fn separate<'a, E: 'a, O: 'a>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>,
) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>
fn separate<'a, E: 'a, O: 'a>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>, ) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>
Separates an option of result.
This method separates an option of result into a pair of options.
§Type Signature
forall e o. Compactable Option => Option (Result o e) -> (Option o, Option e)
§Parameters
fa: The option of result.
§Returns
A pair of options.
§Examples
use fp_library::classes::compactable::Compactable;
use fp_library::brands::OptionBrand;
use fp_library::types::Pair;
let x: Option<Result<i32, &str>> = Some(Ok(5));
let Pair(oks, errs) = OptionBrand::separate(x);
assert_eq!(oks, Some(5));
assert_eq!(errs, None);Source§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 Filterable for OptionBrand
impl Filterable for OptionBrand
Source§fn partition_map<'a, Func, A: 'a, E: 'a, O: 'a>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>
fn partition_map<'a, Func, A: 'a, E: 'a, O: 'a>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>
Partitions an option based on a function that returns a result.
This method partitions an option based on a function that returns a result.
§Type Signature
forall a e o. Filterable Option => (a -> Result o e) -> Option a -> (Option o, Option e)
§Parameters
func: The function to apply.fa: The option to partition.
§Returns
A pair of options.
§Examples
use fp_library::classes::filterable::Filterable;
use fp_library::brands::OptionBrand;
use fp_library::types::Pair;
let x = Some(5);
let Pair(oks, errs) = OptionBrand::partition_map(|a| if a > 2 { Ok(a) } else { Err(a) }, x);
assert_eq!(oks, Some(5));
assert_eq!(errs, None);Source§fn partition<'a, Func, A: 'a + Clone>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>>
fn partition<'a, Func, A: 'a + Clone>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>>
Partitions an option based on a predicate.
This method partitions an option based on a predicate.
§Type Signature
forall a. Filterable Option => (a -> bool) -> Option a -> (Option a, Option a)
§Parameters
func: The predicate.fa: The option to partition.
§Returns
A pair of options.
§Examples
use fp_library::classes::filterable::Filterable;
use fp_library::brands::OptionBrand;
use fp_library::types::Pair;
let x = Some(5);
let Pair(satisfied, not_satisfied) = OptionBrand::partition(|a| a > 2, x);
assert_eq!(satisfied, Some(5));
assert_eq!(not_satisfied, None);Source§fn filter_map<'a, Func, A: 'a, B: 'a>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn filter_map<'a, Func, A: 'a, B: 'a>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Maps a function over an option and filters out None results.
This method maps a function over an option and filters out None results.
§Type Signature
forall a b. Filterable Option => (a -> Option b) -> Option a -> Option b
§Parameters
func: The function to apply.fa: The option to filter and map.
§Returns
The filtered and mapped option.
§Examples
use fp_library::classes::filterable::Filterable;
use fp_library::brands::OptionBrand;
let x = Some(5);
let y = OptionBrand::filter_map(|a| if a > 2 { Some(a * 2) } else { None }, x);
assert_eq!(y, Some(10));Source§fn filter<'a, Func, A: 'a + Clone>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn filter<'a, Func, A: 'a + Clone>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Filters an option based on a predicate.
This method filters an option based on a predicate.
§Type Signature
forall a. Filterable Option => (a -> bool) -> Option a -> Option a
§Parameters
func: The predicate.fa: The option to filter.
§Returns
The filtered option.
§Examples
use fp_library::classes::filterable::Filterable;
use fp_library::brands::OptionBrand;
let x = Some(5);
let y = OptionBrand::filter(|a| a > 2, x);
assert_eq!(y, Some(5));Source§impl Foldable for OptionBrand
impl Foldable for OptionBrand
Source§fn fold_right<'a, FnBrand, Func, A: 'a, B: 'a>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
Func: Fn(A, B) -> B + 'a,
FnBrand: ClonableFn + 'a,
fn fold_right<'a, FnBrand, Func, A: 'a, B: 'a>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
Func: Fn(A, B) -> B + 'a,
FnBrand: ClonableFn + 'a,
Folds the option from the right.
This method performs a right-associative fold of the option. If the option is Some(a), it applies the function to a and the initial value. If None, it returns the initial value.
§Type Signature
forall a b. Foldable Option => ((a, b) -> b, b, Option a) -> b
§Parameters
func: The folding function.initial: The initial value.fa: The option to fold.
§Returns
func(a, initial) if fa is Some(a), otherwise initial.
§Examples
use fp_library::classes::foldable::Foldable;
use fp_library::brands::OptionBrand;
use fp_library::brands::RcFnBrand;
let x = Some(5);
let y = OptionBrand::fold_right::<RcFnBrand, _, _, _>(|a, b| a + b, 10, x);
assert_eq!(y, 15);
// Using the free function
use fp_library::classes::foldable::fold_right;
assert_eq!(fold_right::<RcFnBrand, OptionBrand, _, _, _>(|x: i32, acc| x + acc, 0, Some(5)), 5);
assert_eq!(fold_right::<RcFnBrand, OptionBrand, _, _, _>(|x: i32, acc| x + acc, 0, None), 0);Source§fn fold_left<'a, FnBrand, Func, A: 'a, B: 'a>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
Func: Fn(B, A) -> B + 'a,
FnBrand: ClonableFn + 'a,
fn fold_left<'a, FnBrand, Func, A: 'a, B: 'a>(
func: Func,
initial: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> Bwhere
Func: Fn(B, A) -> B + 'a,
FnBrand: ClonableFn + 'a,
Folds the option from the left.
This method performs a left-associative fold of the option. If the option is Some(a), it applies the function to the initial value and a. If None, it returns the initial value.
§Type Signature
forall a b. Foldable Option => ((b, a) -> b, b, Option a) -> b
§Parameters
func: The function to apply to the accumulator and each element.initial: The initial value of the accumulator.fa: The option to fold.
§Returns
f(initial, a) if fa is Some(a), otherwise initial.
§Examples
use fp_library::classes::foldable::Foldable;
use fp_library::brands::OptionBrand;
use fp_library::brands::RcFnBrand;
let x = Some(5);
let y = OptionBrand::fold_left::<RcFnBrand, _, _, _>(|b, a| b + a, 10, x);
assert_eq!(y, 15);
// Using the free function
use fp_library::classes::foldable::fold_left;
assert_eq!(fold_left::<RcFnBrand, OptionBrand, _, _, _>(|acc, x: i32| acc + x, 0, Some(5)), 5);Source§fn fold_map<'a, FnBrand, Func, A: 'a, M>(
func: Func,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> M
fn fold_map<'a, FnBrand, Func, A: 'a, M>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
Maps the value to a monoid and returns it, or returns empty.
This method maps the element of the option to a monoid. If the option is None, it returns the monoid’s identity element.
§Type Signature
forall a m. (Foldable Option, Monoid m) => ((a) -> m, Option a) -> m
§Parameters
func: The mapping function.fa: The option to fold.
§Returns
func(a) if fa is Some(a), otherwise M::empty().
§Examples
use fp_library::classes::foldable::Foldable;
use fp_library::brands::OptionBrand;
use fp_library::types::string; // Import to bring Monoid impl for String into scope
use fp_library::brands::RcFnBrand;
let x = Some(5);
let y = OptionBrand::fold_map::<RcFnBrand, _, _, _>(|a: i32| a.to_string(), x);
assert_eq!(y, "5".to_string());
// Using the free function
use fp_library::classes::foldable::fold_map;
assert_eq!(fold_map::<RcFnBrand, OptionBrand, _, _, _>(|x: i32| x.to_string(), Some(5)), "5".to_string());Source§impl Functor for OptionBrand
impl Functor for OptionBrand
Source§fn map<'a, F, A: 'a, B: 'a>(
f: F,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>where
F: Fn(A) -> B + 'a,
fn map<'a, F, A: 'a, B: 'a>(
f: F,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>where
F: Fn(A) -> B + 'a,
Maps a function over the value in the option.
This method applies a function to the value inside the option, producing a new option with the transformed value. If the option is None, it returns None.
§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::Functor;
use fp_library::brands::OptionBrand;
let x = Some(5);
let y = OptionBrand::map(|i| i * 2, x);
assert_eq!(y, Some(10));
// Using the free function
use fp_library::classes::functor::map;
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 Kind_cdc7cd43dac7585f for OptionBrand
Generated implementation of Kind_cdc7cd43dac7585f for OptionBrand.
impl Kind_cdc7cd43dac7585f for OptionBrand
Generated implementation of Kind_cdc7cd43dac7585f for OptionBrand.
Source§impl Lift for OptionBrand
impl Lift for OptionBrand
Source§fn lift2<'a, F, A, B, C>(
f: F,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, C>where
F: Fn(A, B) -> C + 'a,
A: 'a,
B: 'a,
C: 'a,
fn lift2<'a, F, A, B, C>(
f: F,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, C>where
F: Fn(A, B) -> C + 'a,
A: 'a,
B: 'a,
C: 'a,
Lifts a binary function into the option context.
This method lifts a binary function to operate on values within 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::Lift;
use fp_library::brands::OptionBrand;
let x = Some(1);
let y = Some(2);
let z = OptionBrand::lift2(|a, b| a + b, x, y);
assert_eq!(z, Some(3));
// Using the free function
use fp_library::classes::lift::lift2;
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<FnBrand: SendClonableFn> ParFoldable<FnBrand> for OptionBrand
impl<FnBrand: SendClonableFn> ParFoldable<FnBrand> for OptionBrand
Source§fn par_fold_map<'a, A, M>(
func: <FnBrand as SendClonableFn>::SendOf<'a, A, M>,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> M
fn par_fold_map<'a, A, M>( func: <FnBrand as SendClonableFn>::SendOf<'a, A, M>, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
Maps the value to a monoid and returns it, or returns empty, in parallel.
This method maps the element of the option to a monoid. Since Option contains at most one element, no actual parallelism occurs, but the interface is satisfied.
§Type Signature
forall a m. (ParFoldable Option, Monoid m, Send m, Sync m) => (f a m, Option a) -> m
§Parameters
func: The mapping function.fa: The option to fold.
§Returns
The combined monoid value.
§Examples
use fp_library::classes::par_foldable::ParFoldable;
use fp_library::brands::{OptionBrand, ArcFnBrand};
use fp_library::classes::send_clonable_fn::SendClonableFn;
use fp_library::classes::send_clonable_fn::new_send;
let x = Some(1);
let f = new_send::<ArcFnBrand, _, _>(|x: i32| x.to_string());
let y = <OptionBrand as ParFoldable<ArcFnBrand>>::par_fold_map(f, x);
assert_eq!(y, "1".to_string());
// Using the free function
use fp_library::classes::par_foldable::par_fold_map;
let x = Some(1);
let f = new_send::<ArcFnBrand, _, _>(|x: i32| x.to_string());
assert_eq!(par_fold_map::<ArcFnBrand, OptionBrand, _, _>(f, x), "1".to_string());Source§fn par_fold_right<'a, A, B>(
func: <FnBrand as SendClonableFn>::SendOf<'a, (A, B), B>,
init: B,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> B
fn par_fold_right<'a, A, B>( func: <FnBrand as SendClonableFn>::SendOf<'a, (A, B), B>, init: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
Source§impl PartialEq for OptionBrand
impl PartialEq for OptionBrand
Source§impl PartialOrd for OptionBrand
impl PartialOrd for OptionBrand
Source§impl Pointed for OptionBrand
impl Pointed for OptionBrand
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 an option.
This method wraps a value in an option context.
§Type Signature
forall a. Pointed Option => a -> Option a
§Parameters
a: The value to wrap.
§Returns
Some(a).
§Examples
use fp_library::classes::pointed::Pointed;
use fp_library::brands::OptionBrand;
let x = OptionBrand::pure(5);
assert_eq!(x, Some(5));
// Using the free function
use fp_library::classes::pointed::pure;
assert_eq!(pure::<OptionBrand, _>(5), Some(5));Source§impl Semiapplicative for OptionBrand
impl Semiapplicative for OptionBrand
Source§fn apply<'a, FnBrand: 'a + ClonableFn, A: 'a + Clone, B: 'a>(
ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as ClonableFn>::Of<'a, A, B>>,
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn apply<'a, FnBrand: 'a + ClonableFn, A: 'a + Clone, B: 'a>( ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as ClonableFn>::Of<'a, A, B>>, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Applies a wrapped function to a wrapped value.
This method applies a function wrapped in an option to a value wrapped in an option.
§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::Semiapplicative;
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));
let x = Some(5);
let y = OptionBrand::apply::<RcFnBrand, i32, i32>(f, x);
assert_eq!(y, Some(10));
// Using the free function
use fp_library::classes::semiapplicative::apply;
let f = Some(<RcFnBrand as ClonableFn>::new(|x: i32| x * 2));
assert_eq!(apply::<RcFnBrand, OptionBrand, _, _>(f, Some(5)), Some(10));Source§impl Semimonad for OptionBrand
impl Semimonad for OptionBrand
Source§fn bind<'a, F, A: 'a, B: 'a>(
ma: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
f: F,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn bind<'a, F, A: 'a, B: 'a>( ma: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, f: F, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Chains option computations.
This method chains two option computations, where the second computation depends on the result of the first.
§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::Semimonad;
use fp_library::brands::OptionBrand;
let x = Some(5);
let y = OptionBrand::bind(x, |i| Some(i * 2));
assert_eq!(y, Some(10));
// Using the free function
use fp_library::classes::semimonad::bind;
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, Func, A: 'a + Clone, B: 'a + Clone>(
func: Func,
ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
Func: Fn(A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
fn traverse<'a, F: Applicative, Func, A: 'a + Clone, B: 'a + Clone>(
func: Func,
ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
Func: Fn(A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
Traverses the option with an applicative function.
This method maps the element of the option to a computation, evaluates it, and wraps the result in the applicative context. If None, it returns pure(None).
§Type Signature
forall a b f. (Traversable Option, Applicative f) => (a -> f b, Option a) -> f (Option b)
§Parameters
func: The function to apply to each element, returning a value in an applicative context.ta: The option to traverse.
§Returns
The option wrapped in the applicative context.
§Examples
use fp_library::classes::traversable::Traversable;
use fp_library::brands::OptionBrand;
let x = Some(5);
let y = OptionBrand::traverse::<OptionBrand, _, _, _>(|a| Some(a * 2), x);
assert_eq!(y, Some(Some(10)));
// Using the free function
use fp_library::classes::traversable::traverse;
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_cdc7cd43dac7585f>::Of<'a, <F as Kind_cdc7cd43dac7585f>::Of<'a, A>>,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>>where
<F as Kind_cdc7cd43dac7585f>::Of<'a, A>: Clone,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>: Clone,
fn sequence<'a, F: Applicative, A: 'a + Clone>(
ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <F as Kind_cdc7cd43dac7585f>::Of<'a, A>>,
) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>>where
<F as Kind_cdc7cd43dac7585f>::Of<'a, A>: Clone,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>: Clone,
Sequences an option of applicative.
This method evaluates the computation inside the option and wraps the result in the applicative context. If None, it returns pure(None).
§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::Traversable;
use fp_library::brands::OptionBrand;
let x = Some(Some(5));
let y = OptionBrand::sequence::<OptionBrand, _>(x);
assert_eq!(y, Some(Some(5)));
// Using the free function
use fp_library::classes::traversable::sequence;
assert_eq!(sequence::<OptionBrand, OptionBrand, _>(Some(Some(5))), Some(Some(5)));Source§impl Witherable for OptionBrand
impl Witherable for OptionBrand
Source§fn wilt<'a, Func, M: Applicative, A: 'a + Clone, E: 'a + Clone, O: 'a + Clone>(
func: Func,
ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>>where
Func: Fn(A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>> + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
fn wilt<'a, Func, M: Applicative, A: 'a + Clone, E: 'a + Clone, O: 'a + Clone>(
func: Func,
ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Pair<<Self as Kind_cdc7cd43dac7585f>::Of<'a, O>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, E>>>where
Func: Fn(A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>> + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,
Result in an applicative context. Read moreSource§fn wither<'a, Func, M: Applicative, A: 'a + Clone, B: 'a + Clone>(
func: Func,
ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
Func: Fn(A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>> + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
fn wither<'a, Func, M: Applicative, A: 'a + Clone, B: 'a + Clone>(
func: Func,
ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>where
Func: Fn(A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>> + 'a,
<Self as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
<M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,
None results in an applicative context. Read moreimpl Copy for OptionBrand
impl Eq for OptionBrand
impl StructuralPartialEq for OptionBrand
Auto Trait Implementations§
impl Freeze for OptionBrand
impl RefUnwindSafe for OptionBrand
impl Send for OptionBrand
impl Sync for OptionBrand
impl Unpin for OptionBrand
impl UnwindSafe for OptionBrand
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