Skip to main content

OptionBrand

Struct OptionBrand 

Source
pub struct OptionBrand;
Expand description

Brand for Option.

Trait Implementations§

Source§

impl Alt for OptionBrand

Source§

fn alt<'a, A: 'a>( fa1: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fa2: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>

Chooses between two options.

Returns the first Some value, or None if both are None.

§Type Signature

forall A. (Option A, Option A) -> Option A

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the value.
§Parameters
  • fa1: The first option.
  • fa2: The second option.
§Returns

The first Some value, or None.

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

assert_eq!(explicit::alt::<OptionBrand, _, _, _>(None, Some(5)), Some(5));
assert_eq!(explicit::alt::<OptionBrand, _, _, _>(Some(3), Some(5)), Some(3));
assert_eq!(explicit::alt::<OptionBrand, _, _, _>(None::<i32>, None), None);
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, 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 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. Option (Option A) -> Option A

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

The flattened option.

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

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

fn separate<'a, E: 'a, O: 'a>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>, ) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)

Separates an option of result.

This method separates an option of result into a pair of options.

§Type Signature

forall E O. Option (Result O E) -> (Option E, Option O)

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

A pair of options.

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

let x: Option<Result<i32, &str>> = Some(Ok(5));
let (errs, oks) = explicit::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, A: 'a, E: 'a, O: 'a>( func: impl Fn(A) -> Result<O, E> + 'a, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)

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. (A -> Result O E, Option A) -> (Option E, Option O)

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

A pair of options.

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

let x = Some(5);
let (errs, oks) = explicit::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: impl Fn(A) -> bool + 'a, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> (<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. (A -> bool, Option A) -> (Option A, Option A)

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the elements.
§Parameters
  • func: The predicate.
  • fa: The option to partition.
§Returns

A pair of options.

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

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

fn filter_map<'a, A: 'a, B: 'a>( func: impl Fn(A) -> Option<B> + 'a, 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. (A -> Option B, Option A) -> Option B

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

The filtered and mapped option.

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

let x = Some(5);
let y = explicit::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: impl Fn(A) -> bool + 'a, 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. (A -> bool, Option A) -> Option A

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the elements.
§Parameters
  • func: The predicate.
  • fa: The option to filter.
§Returns

The filtered option.

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

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

impl Foldable for OptionBrand

Source§

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

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

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

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

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

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

fn fold_map<'a, FnBrand, A: 'a + Clone, M>( func: impl Fn(A) -> M + 'a, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
where M: Monoid + 'a, FnBrand: CloneFn + '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 A M. (Monoid M, CloneFn FnBrand) => (A -> M, Option A) -> M

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the elements in the structure.
  • M: The type of the monoid.
§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::*,
};

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

impl FoldableWithIndex for OptionBrand

Source§

fn fold_map_with_index<'a, FnBrand, A: 'a + Clone, R: Monoid + 'a>( f: impl Fn((), A) -> R + 'a, fa: Option<A>, ) -> R
where FnBrand: LiftFn + 'a,

Folds the option using a monoid, providing the index ().

§Type Signature

forall A R. (Monoid R, LiftFn FnBrand) => (((), A) -> R, Option A) -> R

§Type Parameters
  • 'a: The lifetime of the value.
  • FnBrand: The brand of the cloneable function to use.
  • A: The type of the value inside the option.
  • R: The monoid type.
§Parameters
  • f: The function to apply to the value and its index.
  • fa: The option to fold.
§Returns

The monoid value.

§Examples
use fp_library::{
	brands::*,
	classes::foldable_with_index::FoldableWithIndex,
	functions::*,
};
let x = Some(5);
let y = <OptionBrand as FoldableWithIndex>::fold_map_with_index::<RcFnBrand, _, _>(
	|_, i: i32| i.to_string(),
	x,
);
assert_eq!(y, "5".to_string());
Source§

fn fold_right_with_index<'a, FnBrand, A: 'a + Clone, B: 'a>( func: impl Fn(Self::Index, A, B) -> B + 'a, initial: B, fa: Self::Of<'a, A>, ) -> B
where FnBrand: LiftFn + 'a, Self::Index: 'a,

Folds the structure with index by applying a function from right to left. Read more
Source§

fn fold_left_with_index<'a, FnBrand, A: 'a + Clone, B: 'a>( func: impl Fn(Self::Index, B, A) -> B + 'a, initial: B, fa: Self::Of<'a, A>, ) -> B
where FnBrand: LiftFn + 'a, Self::Index: 'a,

Folds the structure with index by applying a function from left to right. Read more
Source§

impl Functor for OptionBrand

Source§

fn map<'a, A: 'a, B: 'a>( func: impl Fn(A) -> B + 'a, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

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. (A -> B, Option A) -> Option B

§Type Parameters
  • 'a: The lifetime of the value.
  • A: The type of the value inside the option.
  • B: The type of the result of applying the function.
§Parameters
  • func: 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::{
	brands::*,
	functions::*,
};

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

impl FunctorWithIndex for OptionBrand

Source§

fn map_with_index<'a, A: 'a, B: 'a>( f: impl Fn((), A) -> B + 'a, fa: Option<A>, ) -> Option<B>

Maps a function over the value in the option, providing the index ().

§Type Signature

forall A B. (((), A) -> B, Option A) -> Option B

§Type Parameters
  • 'a: The lifetime of the value.
  • A: The type of the value inside the option.
  • B: The type of the result of applying the function.
§Parameters
  • f: The function to apply to the value and its index.
  • fa: The option to map over.
§Returns

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

§Examples
use fp_library::{
	brands::OptionBrand,
	classes::functor_with_index::FunctorWithIndex,
	functions::*,
};
let x = Some(5);
let y = <OptionBrand as FunctorWithIndex>::map_with_index(|_, 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>

The applied type.
Source§

impl Lift for OptionBrand

Source§

fn lift2<'a, A, B, C>( func: impl Fn(A, B) -> C + 'a, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, C>
where 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. ((A, B) -> C, Option A, Option B) -> Option C

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the first option’s value.
  • B: The type of the second option’s value.
  • C: The return type of the function.
§Parameters
  • func: 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::{
	brands::*,
	functions::*,
};

let x = Some(1);
let y = Some(2);
let z = explicit::lift2::<OptionBrand, _, _, _, _, _, _>(|a, b| a + b, x, y);
assert_eq!(z, Some(3));
Source§

impl MonadRec for OptionBrand

Source§

fn tail_rec_m<'a, A: 'a, B: 'a>( func: impl Fn(A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, ControlFlow<B, A>> + 'a, initial: A, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

Performs tail-recursive monadic computation over Option.

Iteratively applies the step function. If the function returns None, the computation short-circuits. If it returns Some(ControlFlow::Continue(a)), the loop continues with the new state. If it returns Some(ControlFlow::Break(b)), the computation completes with Some(b).

§Type Signature

forall A B. (A -> Option (ControlFlow B A), A) -> Option B

§Type Parameters
  • 'a: The lifetime of the computation.
  • A: The type of the initial value and loop state.
  • B: The type of the result.
§Parameters
  • func: The step function.
  • initial: The initial value.
§Returns

The result of the computation, or None if the step function returned None.

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

let result = tail_rec_m::<OptionBrand, _, _>(
	|n| {
		if n < 10 { Some(ControlFlow::Continue(n + 1)) } else { Some(ControlFlow::Break(n)) }
	},
	0,
);
assert_eq!(result, Some(10));
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 Plus for OptionBrand

Source§

fn empty<'a, A: 'a>() -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>

Returns None, the identity element for alt.

§Type Signature

forall A. () -> Option A

§Type Parameters
  • 'a: The lifetime of the value.
  • A: The type of the value.
§Returns

None.

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

let x: Option<i32> = plus_empty::<OptionBrand, i32>();
assert_eq!(x, None);
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. A -> Option A

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

Some(a).

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

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

impl RefAlt for OptionBrand

Source§

fn ref_alt<'a, A: 'a + Clone>( fa1: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fa2: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>

Chooses between two options by reference.

Returns the first Some value (cloned), or None if both are None. This is the by-reference counterpart of Alt::alt for Option, borrowing both arguments and cloning the inner value as needed.

§Type Signature

forall A. (&Option A, &Option A) -> Option A

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the value.
§Parameters
  • fa1: The first option.
  • fa2: The second option.
§Returns

The first Some value (cloned), or None.

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

assert_eq!(explicit::alt::<OptionBrand, _, _, _>(&None, &Some(5)), Some(5));
assert_eq!(explicit::alt::<OptionBrand, _, _, _>(&Some(3), &Some(5)), Some(3));
assert_eq!(explicit::alt::<OptionBrand, _, _, _>(&None::<i32>, &None), None);
Source§

impl RefCompactable for OptionBrand

Source§

fn ref_compact<'a, A: 'a + Clone>( fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, Option<A>>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>

Compacts a borrowed nested option by reference.

Flattens a borrowed Option<Option<A>> into an Option<A>, cloning the inner value if present.

§Type Signature

forall A. &Option (Option A) -> Option A

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the elements. Must be Clone because elements are extracted from a borrowed container.
§Parameters
  • fa: A reference to the nested option.
§Returns

The flattened option with the inner value cloned, or None.

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

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

let z: Option<Option<i32>> = Some(None);
let w = explicit::compact::<OptionBrand, _, _, _>(&z);
assert_eq!(w, None);
Source§

fn ref_separate<'a, E: 'a + Clone, O: 'a + Clone>( fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>, ) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)

Separates a borrowed option of result by reference.

Splits a borrowed Option<Result<O, E>> into a pair of options, cloning the inner value. The first element contains the error if present, the second contains the success value.

§Type Signature

forall E O. &Option (Result O E) -> (Option E, Option O)

§Type Parameters
  • 'a: The lifetime of the values.
  • E: The type of the error value. Must be Clone because elements are extracted from a borrowed container.
  • O: The type of the success value. Must be Clone because elements are extracted from a borrowed container.
§Parameters
  • fa: A reference to the option of result.
§Returns

A pair of options: the first containing the cloned error, the second containing the cloned success value.

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

let x: Option<Result<i32, &str>> = Some(Ok(5));
let (errs, oks) = explicit::separate::<OptionBrand, _, _, _, _>(&x);
assert_eq!(oks, Some(5));
assert_eq!(errs, None);

let y: Option<Result<i32, &str>> = Some(Err("bad"));
let (errs, oks) = explicit::separate::<OptionBrand, _, _, _, _>(&y);
assert_eq!(oks, None);
assert_eq!(errs, Some("bad"));
Source§

impl RefFilterable for OptionBrand

Source§

fn ref_filter_map<'a, A: 'a, B: 'a>( func: impl Fn(&A) -> Option<B> + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

Filters and maps the option by reference.

§Type Signature

forall A B. (&A -> Option B, &Option A) -> Option B

§Type Parameters
  • 'a: The lifetime.
  • A: The input type.
  • B: The output type.
§Parameters
  • func: The function.
  • fa: The option.
§Returns

The filtered option.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
let result = explicit::filter_map::<OptionBrand, _, _, _, _>(
	|x: &i32| if *x > 3 { Some(*x) } else { None },
	&Some(5),
);
assert_eq!(result, Some(5));
Source§

fn ref_partition_map<'a, A: 'a, E: 'a, O: 'a>( func: impl Fn(&A) -> Result<O, E> + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)

Partitions a structure by reference using a function that returns Result. Read more
Source§

fn ref_partition<'a, A: 'a + Clone>( func: impl Fn(&A) -> bool + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>)

Partitions a structure by reference using a predicate. Read more
Source§

fn ref_filter<'a, A: 'a + Clone>( func: impl Fn(&A) -> bool + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>

Filters a structure by reference using a predicate. Read more
Source§

impl RefFoldable for OptionBrand

Source§

fn ref_fold_map<'a, FnBrand, A: 'a + Clone, M>( func: impl Fn(&A) -> M + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
where FnBrand: LiftFn + 'a, M: Monoid + 'a,

Folds the option by reference.

§Type Signature

forall A M. (LiftFn FnBrand, Monoid M) => (&A -> M, &Option A) -> M

§Type Parameters
  • 'a: The lifetime.
  • FnBrand: The brand.
  • A: The element type.
  • M: The monoid type.
§Parameters
  • func: The mapping function.
  • fa: The option.
§Returns

The monoid value.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
let result =
	explicit::fold_map::<RcFnBrand, OptionBrand, _, _, _, _>(|x: &i32| x.to_string(), &Some(5));
assert_eq!(result, "5");
Source§

fn ref_fold_right<'a, FnBrand, A: 'a + Clone, B: 'a>( func: impl Fn(&A, B) -> B + 'a, initial: B, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where FnBrand: LiftFn + 'a,

Folds the structure from the right by reference. Read more
Source§

fn ref_fold_left<'a, FnBrand, A: 'a + Clone, B: 'a>( func: impl Fn(B, &A) -> B + 'a, initial: B, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where FnBrand: LiftFn + 'a,

Folds the structure from the left by reference. Read more
Source§

impl RefFoldableWithIndex for OptionBrand

Source§

fn ref_fold_map_with_index<'a, FnBrand, A: 'a + Clone, R: Monoid + 'a>( func: impl Fn((), &A) -> R + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> R
where FnBrand: LiftFn + 'a,

Folds by reference with index (always ()).

§Type Signature

forall A R. (Monoid R, LiftFn FnBrand) => (((), &A) -> R, &Option A) -> R

§Type Parameters
  • 'a: The lifetime.
  • FnBrand: The brand of the cloneable function.
  • A: The element type.
  • R: The monoid type.
§Parameters
  • func: The function.
  • fa: The option.
§Returns

The monoid value.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
let result = explicit::fold_map_with_index::<RcFnBrand, OptionBrand, _, _, _, _>(
	|(), x: &i32| x.to_string(),
	&Some(5),
);
assert_eq!(result, "5");
Source§

fn ref_fold_right_with_index<'a, FnBrand, A: 'a + Clone, B: 'a>( func: impl Fn(Self::Index, &A, B) -> B + 'a, initial: B, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where FnBrand: LiftFn + 'a, Self::Index: 'a,

Folds the structure from the right by reference, providing the index. Read more
Source§

fn ref_fold_left_with_index<'a, FnBrand, A: 'a + Clone, B: 'a>( func: impl Fn(Self::Index, B, &A) -> B + 'a, initial: B, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where FnBrand: LiftFn + 'a, Self::Index: 'a,

Folds the structure from the left by reference, providing the index. Read more
Source§

impl RefFunctor for OptionBrand

Source§

fn ref_map<'a, A: 'a, B: 'a>( func: impl Fn(&A) -> B + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

Maps a function over the option by reference.

§Type Signature

forall A B. (&A -> B, &Option A) -> Option B

§Type Parameters
  • 'a: The lifetime.
  • A: The input type.
  • B: The output type.
§Parameters
  • func: The function.
  • fa: The option.
§Returns

The mapped option.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
assert_eq!(explicit::map::<OptionBrand, _, _, _, _>(|x: &i32| *x * 2, &Some(5)), Some(10));
Source§

impl RefFunctorWithIndex for OptionBrand

Source§

fn ref_map_with_index<'a, A: 'a, B: 'a>( func: impl Fn((), &A) -> B + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

Maps by reference with index (always ()).

§Type Signature

forall A B. (((), &A) -> B, &Option A) -> Option B

§Type Parameters
  • 'a: The lifetime.
  • A: The input type.
  • B: The output type.
§Parameters
  • func: The function.
  • fa: The option.
§Returns

The mapped option.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
assert_eq!(
	explicit::map_with_index::<OptionBrand, _, _, _, _>(|(), x: &i32| *x * 2, &Some(5)),
	Some(10),
);
Source§

impl RefLift for OptionBrand

Source§

fn ref_lift2<'a, A: 'a, B: 'a, C: 'a>( func: impl Fn(&A, &B) -> C + 'a, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, C>

Combines two Option values with a by-reference binary function.

§Type Signature

forall A B C. ((&A, &B) -> C, &Option A, &Option B) -> Option C

§Type Parameters
  • 'a: The lifetime.
  • A: First input type.
  • B: Second input type.
  • C: Output type.
§Parameters
  • func: The binary function.
  • fa: The first option.
  • fb: The second option.
§Returns

The combined result, or None if either input is None.

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

let result = explicit::lift2::<OptionBrand, _, _, _, _, _, _>(
	|a: &i32, b: &i32| *a + *b,
	&Some(1),
	&Some(2),
);
assert_eq!(result, Some(3));
Source§

impl RefPointed for OptionBrand

Source§

fn ref_pure<'a, A: Clone + 'a>( a: &A, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>

Creates a Some from a reference by cloning.

§Type Signature

forall A. &A -> Option A

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

A Some containing a clone of the value.

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

let x = 42;
let result: Option<i32> = ref_pure::<OptionBrand, _>(&x);
assert_eq!(result, Some(42));
Source§

impl RefSemiapplicative for OptionBrand

Source§

fn ref_apply<'a, FnBrand: 'a + CloneFn<Ref>, A: 'a, B: 'a>( ff: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as CloneFn<Ref>>::Of<'a, A, B>>, fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

Applies a wrapped by-ref function to an Option value.

§Type Signature

forall A B. CloneFn FnBrand => (&Option (FnBrand A B), &Option A) -> Option B

§Type Parameters
  • 'a: The lifetime.
  • FnBrand: The function brand.
  • A: The input type.
  • B: The output type.
§Parameters
  • ff: The option containing the by-ref function.
  • fa: The option containing the value.
§Returns

The result of applying the function, or None.

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

let f: std::rc::Rc<dyn Fn(&i32) -> i32> = std::rc::Rc::new(|x: &i32| *x + 1);
let result = ref_apply::<RcFnBrand, OptionBrand, _, _>(&Some(f), &Some(5));
assert_eq!(result, Some(6));
Source§

impl RefSemimonad for OptionBrand

Source§

fn ref_bind<'a, A: 'a, B: 'a>( fa: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, f: impl Fn(&A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>

Chains Option computations by reference.

§Type Signature

forall A B. (&Option A, &A -> Option B) -> Option B

§Type Parameters
  • 'a: The lifetime.
  • A: The input type.
  • B: The output type.
§Parameters
  • fa: The input option.
  • f: The function to apply by reference.
§Returns

The result of applying the function, or None.

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

let result: Option<String> =
	explicit::bind::<OptionBrand, _, _, _, _>(&Some(42), |x: &i32| Some(x.to_string()));
assert_eq!(result, Some("42".to_string()));
Source§

impl RefTraversable for OptionBrand

Source§

fn ref_traverse<'a, FnBrand, A: 'a + Clone, B: 'a + Clone, F: Applicative>( func: impl Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where FnBrand: LiftFn + 'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone, <F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,

Traverses the option by reference.

§Type Signature

forall A B F. (Applicative F, LiftFn FnBrand) => (&A -> F B, &Option A) -> F (Option B)

§Type Parameters
  • 'a: The lifetime.
  • FnBrand: The brand.
  • A: The input type.
  • B: The output type.
  • F: The applicative.
§Parameters
  • func: The function.
  • ta: The option.
§Returns

The traversed result.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
let result: Vec<Option<String>> = ref_traverse::<OptionBrand, RcFnBrand, _, _, VecBrand>(
	|x: &i32| vec![x.to_string()],
	&Some(5),
);
assert_eq!(result, vec![Some("5".to_string())]);
Source§

impl RefTraversableWithIndex for OptionBrand

Source§

fn ref_traverse_with_index<'a, A: 'a + Clone, B: 'a + Clone, M: Applicative>( f: impl Fn((), &A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone, <M as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,

Traverses by reference with index (always ()).

§Type Signature

forall A B M. Applicative M => (((), &A) -> M B, &Option A) -> M (Option B)

§Type Parameters
  • 'a: The lifetime.
  • A: The input type.
  • B: The output type.
  • M: The applicative.
§Parameters
  • f: The function.
  • ta: The option.
§Returns

The traversed result.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
let result: Vec<Option<String>> =
	explicit::traverse_with_index::<RcFnBrand, OptionBrand, _, _, VecBrand, _, _>(
		|(), x: &i32| vec![x.to_string()],
		&Some(5),
	);
assert_eq!(result, vec![Some("5".to_string())]);
Source§

impl RefWitherable for OptionBrand

Source§

fn ref_wilt<'a, FnBrand, M: Applicative, A: 'a + Clone, E: 'a + Clone, O: 'a + Clone>( func: impl Fn(&A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>> + 'a, ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)>
where FnBrand: LiftFn + 'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone, <M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>: Clone,

Partitions by reference in an applicative context. Read more
Source§

fn ref_wither<'a, FnBrand, M: Applicative, A: 'a + Clone, B: 'a + Clone>( func: impl Fn(&A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>> + 'a, ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where FnBrand: LiftFn + 'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone, <M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>>: Clone,

Filters by reference in an applicative context. Read more
Source§

impl Semiapplicative for OptionBrand

Source§

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

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function wrapper.
  • A: The type of the input value.
  • B: The type of the output 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(lift_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, A: 'a, B: 'a>( ma: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, func: impl Fn(A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, ) -> <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. (Option A, A -> Option B) -> Option B

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the result of the first computation.
  • B: The type of the result of the second computation.
§Parameters
  • ma: The first option.
  • func: 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::{
	brands::OptionBrand,
	functions::*,
};

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

impl Traversable for OptionBrand

Source§

fn traverse<'a, A: 'a + Clone, B: 'a + Clone, F: Applicative>( func: impl Fn(A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where <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. Applicative F => (A -> F B, Option A) -> F (Option B)

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the elements in the traversable structure.
  • B: The type of the elements in the resulting traversable structure.
  • F: The applicative context.
§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::{
	brands::*,
	functions::*,
};

let x = Some(5);
let y =
	explicit::traverse::<RcFnBrand, OptionBrand, _, _, OptionBrand, _, _>(|a| Some(a * 2), x);
assert_eq!(y, Some(Some(10)));
Source§

fn sequence<'a, A: 'a + Clone, F: Applicative>( 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. Applicative F => Option (F A) -> F (Option A)

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

The result of the traversal.

§Returns

The option wrapped in the applicative context.

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

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

impl TraversableWithIndex for OptionBrand

Source§

fn traverse_with_index<'a, A: 'a, B: 'a + Clone, M: Applicative>( f: impl Fn((), A) -> M::Of<'a, B> + 'a, ta: Option<A>, ) -> M::Of<'a, Option<B>>

Traverses the option with an applicative function, providing the index ().

§Type Signature

forall A B M. Applicative M => (((), A) -> M B, Option A) -> M (Option B)

§Type Parameters
  • 'a: The lifetime of the value.
  • A: The type of the value inside the option.
  • B: The type of the result.
  • M: The applicative context.
§Parameters
  • f: The function to apply to the value and its index, returning a value in an applicative context.
  • ta: The option to traverse.
§Returns

The option wrapped in the applicative context.

§Examples
use fp_library::{
	brands::OptionBrand,
	classes::traversable_with_index::TraversableWithIndex,
	functions::*,
};
let x = Some(5);
let y = <OptionBrand as TraversableWithIndex>::traverse_with_index::<i32, i32, OptionBrand>(
	|_, i| Some(i * 2),
	x,
);
assert_eq!(y, Some(Some(10)));
Source§

impl WithIndex for OptionBrand

Source§

type Index = ()

The index type for this structure. Read more
Source§

impl Witherable for OptionBrand

Source§

fn wilt<'a, M: Applicative, A: 'a + Clone, E: 'a + Clone, O: 'a + Clone>( func: impl Fn(A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>> + 'a, ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)>
where <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 A E O. Applicative M => (A -> M (Result O E), Option A) -> M (Option E, Option O)

§Type Parameters
  • 'a: The lifetime of the values.
  • M: The applicative context.
  • A: The type of the elements in the input structure.
  • E: The type of the error values.
  • O: The type of the success values.
§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::{
	brands::*,
	functions::*,
};

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

fn wither<'a, M: Applicative, A: 'a + Clone, B: 'a + Clone>( func: impl Fn(A) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, Option<B>> + 'a, ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <M as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where <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 A B. Applicative M => (A -> M (Option B), Option A) -> M (Option B)

§Type Parameters
  • 'a: The lifetime of the values.
  • M: The applicative context.
  • A: The type of the elements in the input structure.
  • B: The type of the result of applying the function.
§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::{
	brands::*,
	functions::*,
};

let x = Some(5);
let y = explicit::wither::<RcFnBrand, 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> Pipe for T

Source§

fn pipe<B>(self, f: impl FnOnce(Self) -> B) -> B

Pipes self into a function, enabling left-to-right composition. 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<Brand> RefApplyFirst for Brand
where Brand: RefLift,

Source§

fn ref_apply_first<'a, A: Clone + 'a, B: 'a>( 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. Read more
Source§

impl<Brand> RefApplySecond for Brand
where Brand: RefLift,

Source§

fn ref_apply_second<'a, A: 'a, B: Clone + 'a>( 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. 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> Alternative for Brand
where Brand: Applicative + Plus,

Source§

impl<Brand> Applicative for Brand

Source§

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

Source§

impl<Brand> MonadPlus for Brand
where Brand: Monad + Alternative,

Source§

impl<Brand> RefApplicative for Brand

Source§

impl<Brand> RefMonad for Brand