OptionBrand

Struct OptionBrand 

Source
pub struct OptionBrand;
Expand description

Brand for Option.

Trait Implementations§

Source§

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>

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

impl ApplySecond for OptionBrand

Source§

fn apply_second<'a, B: 'a + Clone, A: '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 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 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>

Compacts a nested option.

This method flattens a nested option.

§Type Signature

forall a. Compactable Option => Option (Option a) -> Option a

§Type Parameters
  • A: The type of the elements.
§Parameters
  • fa: The nested option.
§Returns

The flattened option.

§Examples
use fp_library::functions::*;
use fp_library::brands::OptionBrand;

let x = Some(Some(5));
let y = compact::<OptionBrand, _>(x);
assert_eq!(y, Some(5));
Source§

fn separate<'a, O: 'a, E: '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 o e. Compactable Option => Option (Result o e) -> (Option o, Option e)

§Type Parameters
  • O: The type of the success value.
  • E: The type of the error value.
§Parameters
  • fa: The option of result.
§Returns

A pair of options.

§Examples
use fp_library::{brands::*, functions::*, types::*};

let x: Option<Result<i32, &str>> = Some(Ok(5));
let Pair(oks, errs) = separate::<OptionBrand, _, _>(x);
assert_eq!(oks, Some(5));
assert_eq!(errs, None);
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 Filterable for OptionBrand

Source§

fn partition_map<'a, O: 'a, E: 'a, A: 'a, Func>( 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>>
where Func: Fn(A) -> Result<O, E> + 'a,

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 o e a. Filterable Option => (a -> Result o e, Option a) -> Pair (Option o) (Option e)

§Type Parameters
  • O: The type of the success value.
  • E: The type of the error value.
  • A: The type of the input value.
  • Func: The type of the function to apply.
§Parameters
  • func: The function to apply.
  • fa: The option to partition.
§Returns

A pair of options.

§Examples
use fp_library::{brands::*, functions::*, types::*};

let x = Some(5);
let Pair(oks, errs) = partition_map::<OptionBrand, _, _, _, _>(|a| if a > 2 { Ok(a) } else { Err(a) }, x);
assert_eq!(oks, Some(5));
assert_eq!(errs, None);
Source§

fn partition<'a, A: 'a + Clone, Func>( 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>>
where Func: Fn(A) -> bool + '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) -> Pair (Option a) (Option a)

§Type Parameters
  • A: The type of the elements.
  • Func: The type of the predicate.
§Parameters
  • func: The predicate.
  • fa: The option to partition.
§Returns

A pair of options.

§Examples
use fp_library::{brands::*, functions::*, types::*};

let x = Some(5);
let Pair(satisfied, not_satisfied) = partition::<OptionBrand, _, _>(|a| a > 2, x);
assert_eq!(satisfied, Some(5));
assert_eq!(not_satisfied, None);
Source§

fn filter_map<'a, B: 'a, A: 'a, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
where Func: Fn(A) -> Option<B> + 'a,

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 b a. Filterable Option => (a -> Option b, Option a) -> Option b

§Type Parameters
  • B: The type of the result of applying the function.
  • A: The type of the input value.
  • Func: The type of the function to apply.
§Parameters
  • func: The function to apply.
  • fa: The option to filter and map.
§Returns

The filtered and mapped option.

§Examples
use fp_library::functions::*;
use fp_library::brands::OptionBrand;

let x = Some(5);
let y = filter_map::<OptionBrand, _, _, _>(|a| if a > 2 { Some(a * 2) } else { None }, x);
assert_eq!(y, Some(10));
Source§

fn filter<'a, A: 'a + Clone, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
where Func: Fn(A) -> bool + '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

§Type Parameters
  • A: The type of the elements.
  • Func: The type of the predicate.
§Parameters
  • func: The predicate.
  • fa: The option to filter.
§Returns

The filtered option.

§Examples
use fp_library::functions::*;
use fp_library::brands::OptionBrand;

let x = Some(5);
let y = filter::<OptionBrand, _, _>(|a| a > 2, x);
assert_eq!(y, Some(5));
Source§

impl Foldable for OptionBrand

Source§

fn fold_right<'a, FnBrand, B: 'a, A: 'a, Func>( func: Func, initial: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where Func: Fn(A, B) -> B + 'a, FnBrand: CloneableFn + '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 b a. Foldable Option => ((a, b) -> b, b, Option a) -> b

§Type Parameters
  • FnBrand: The brand of the cloneable function to use.
  • B: The type of the accumulator.
  • A: The type of the elements in the structure.
  • Func: The type of the folding function.
§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::functions::*;
use fp_library::brands::{OptionBrand, RcFnBrand};

let x = Some(5);
let y = fold_right::<RcFnBrand, OptionBrand, _, _, _>(|a, b| a + b, 10, x);
assert_eq!(y, 15);
Source§

fn fold_left<'a, FnBrand, B: 'a, A: 'a, Func>( func: Func, initial: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where Func: Fn(B, A) -> B + 'a, FnBrand: CloneableFn + '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 b a. Foldable Option => ((b, a) -> b, b, Option a) -> b

§Type Parameters
  • FnBrand: The brand of the cloneable function to use.
  • B: The type of the accumulator.
  • A: The type of the elements in the structure.
  • 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 option to fold.
§Returns

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

§Examples
use fp_library::functions::*;
use fp_library::brands::{OptionBrand, RcFnBrand};

let x = Some(5);
let y = fold_left::<RcFnBrand, OptionBrand, _, _, _>(|b, a| b + a, 10, x);
assert_eq!(y, 15);
Source§

fn fold_map<'a, FnBrand, M, A: 'a, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
where M: Monoid + 'a, Func: Fn(A) -> M + 'a, FnBrand: CloneableFn + 'a,

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 m a. (Foldable Option, Monoid m) => ((a) -> m, Option a) -> m

§Type Parameters
  • FnBrand: The brand of the cloneable function to use.
  • M: The type of the monoid.
  • A: The type of the elements in the structure.
  • Func: The type of the mapping function.
§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::{brands::*, functions::*, types::*};

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

impl Functor for OptionBrand

Source§

fn map<'a, B: 'a, A: 'a, F>( 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 b a. Functor Option => (a -> b, Option a) -> Option b

§Type Parameters
  • B: The type of the result of applying the function.
  • A: The type of the value inside the option.
  • F: The type of the function to apply.
§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::functions::*;
use fp_library::brands::OptionBrand;

let x = Some(5);
let y = map::<OptionBrand, _, _, _>(|i| i * 2, x);
assert_eq!(y, Some(10));
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_cdc7cd43dac7585f for OptionBrand

Generated implementation of Kind_cdc7cd43dac7585f for OptionBrand.

Source§

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

Source§

impl Lift for OptionBrand

Source§

fn lift2<'a, C, A, B, F>( 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 c a b. Lift Option => ((a, b) -> c, Option a, Option b) -> Option c

§Type Parameters
  • C: The return type of the function.
  • A: The type of the first option’s value.
  • B: The type of the second option’s value.
  • F: The type of the binary function.
§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::functions::*;
use fp_library::brands::OptionBrand;

let x = Some(1);
let y = Some(2);
let z = lift2::<OptionBrand, _, _, _, _>(|a, b| a + b, x, y);
assert_eq!(z, Some(3));
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<FnBrand: SendCloneableFn> ParFoldable<FnBrand> for OptionBrand

Source§

fn par_fold_map<'a, M, A>( func: <FnBrand as SendCloneableFn>::SendOf<'a, A, M>, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
where A: 'a + Clone + Send + Sync, M: Monoid + Send + Sync + 'a,

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 fn_brand m a. (ParFoldable Option, Monoid m, Send m, Sync m) => (fn_brand a m, Option a) -> m

§Type Parameters
  • M: The monoid type (must be Send + Sync).
  • A: The element type (must be Send + Sync).
§Parameters
  • func: The mapping function.
  • fa: The option to fold.
§Returns

The combined monoid value.

§Examples
use fp_library::functions::*;
use fp_library::brands::{OptionBrand, ArcFnBrand};

let x = Some(1);
let f = send_cloneable_fn_new::<ArcFnBrand, _, _>(|x: i32| x.to_string());
let y = par_fold_map::<ArcFnBrand, OptionBrand, _, _>(f, x);
assert_eq!(y, "1".to_string());
Source§

fn par_fold_right<'a, B, A>( func: <FnBrand as SendCloneableFn>::SendOf<'a, (A, B), B>, init: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where A: 'a + Clone + Send + Sync, B: Send + Sync + 'a, FnBrand: 'a,

Parallel version of fold_right. 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_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

§Type Parameters
  • A: The type of the value to wrap.
§Parameters
  • a: The value to wrap.
§Returns

Some(a).

§Examples
use fp_library::functions::*;
use fp_library::brands::OptionBrand;

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

impl Semiapplicative for OptionBrand

Source§

fn apply<'a, FnBrand: 'a + CloneableFn, B: 'a, A: 'a + Clone>( ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as CloneableFn>::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 fn_brand b a. Semiapplicative Option => (Option (fn_brand a b), Option a) -> Option b

§Type Parameters
  • FnBrand: The brand of the cloneable function wrapper.
  • B: The type of the output value.
  • A: The type of the input value.
§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::{brands::*, classes::*, functions::*};

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

impl Semimonad for OptionBrand

Source§

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

Chains option computations.

This method chains two option computations, where the second computation depends on the result of the first.

§Type Signature

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

§Type Parameters
  • B: The type of the result of the second computation.
  • A: The type of the result of the first computation.
  • F: The type of the function to apply.
§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::functions::*;
use fp_library::brands::OptionBrand;

let x = Some(5);
let y = bind::<OptionBrand, _, _, _>(x, |i| Some(i * 2));
assert_eq!(y, Some(10));
Source§

impl Traversable for OptionBrand

Source§

fn traverse<'a, F: Applicative, B: 'a + Clone, A: 'a + Clone, Func>( 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 f b a. (Traversable Option, Applicative f) => (a -> f b, Option a) -> f (Option b)

§Type Parameters
  • F: The applicative context.
  • B: The type of the elements in the resulting traversable structure.
  • A: The type of the elements in the traversable structure.
  • Func: The type of the function to apply.
§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::functions::*;
use fp_library::brands::OptionBrand;

let x = Some(5);
let y = traverse::<OptionBrand, OptionBrand, _, _, _>(|a| Some(a * 2), x);
assert_eq!(y, 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,

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 f a. (Traversable Option, Applicative f) => (Option (f a)) -> f (Option a)

§Type Parameters
  • F: The applicative context.
  • A: The type of the elements in the traversable structure.
§Parameters
  • ta: The option containing the applicative value.
§Returns

The option wrapped in the applicative context.

§Examples
use fp_library::functions::*;
use fp_library::brands::OptionBrand;

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

impl Witherable for OptionBrand

Source§

fn wilt<'a, M: Applicative, O: 'a + Clone, E: 'a + Clone, A: 'a + Clone, Func>( 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,

Partitions an option based on a function that returns a result in an applicative context.

This method partitions an option based on a function that returns a result in an applicative context.

§Type Signature

forall m o e a. (Witherable Option, Applicative m) => (a -> m (Result o e), Option a) -> m (Pair (Option o) (Option e))

§Type Parameters
  • M: The applicative context.
  • O: The type of the success values.
  • E: The type of the error values.
  • A: The type of the elements in the input structure.
  • Func: The type of the function to apply.
§Parameters
  • func: The function to apply to each element, returning a Result in an applicative context.
  • ta: The option to partition.
§Returns

The partitioned option wrapped in the applicative context.

§Examples
use fp_library::{functions::*, brands::*, types::*};

let x = Some(5);
let y = wilt::<OptionBrand, OptionBrand, _, _, _, _>(|a| Some(if a > 2 { Ok(a) } else { Err(a) }), x);
assert_eq!(y, Some(Pair(Some(5), None)));
Source§

fn wither<'a, M: Applicative, B: 'a + Clone, A: 'a + Clone, Func>( 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,

Maps a function over an option and filters out None results in an applicative context.

This method maps a function over an option and filters out None results in an applicative context.

§Type Signature

forall m b a. (Witherable Option, Applicative m) => (a -> m (Option b), Option a) -> m (Option b)

§Type Parameters
  • M: The applicative context.
  • B: The type of the result of applying the function.
  • A: The type of the elements in the input structure.
  • Func: The type of the function to apply.
§Parameters
  • func: The function to apply to each element, returning an Option in an applicative context.
  • ta: The option to filter and map.
§Returns

The filtered and mapped option wrapped in the applicative context.

§Examples
use fp_library::{functions::*, brands::*};

let x = Some(5);
let y = wither::<OptionBrand, OptionBrand, _, _, _>(|a| Some(if a > 2 { Some(a * 2) } else { None }), x);
assert_eq!(y, Some(Some(10)));
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> 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,