PairWithFirstBrand

Struct PairWithFirstBrand 

Source
pub struct PairWithFirstBrand<First>(/* private fields */);
Expand description

Brand for the partially-applied form of crate::types::Pair with the first value filled in.

Trait Implementations§

Source§

impl<First: Clone + Semigroup + 'static> ApplyFirst for PairWithFirstBrand<First>

Source§

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

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

impl<First: Clone + Semigroup + 'static> ApplySecond for PairWithFirstBrand<First>

Source§

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

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

impl<First: Clone> Clone for PairWithFirstBrand<First>

Source§

fn clone(&self) -> PairWithFirstBrand<First>

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<First: Debug> Debug for PairWithFirstBrand<First>

Source§

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

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

impl<First: Default> Default for PairWithFirstBrand<First>

Source§

fn default() -> PairWithFirstBrand<First>

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

impl<First: 'static> Foldable for PairWithFirstBrand<First>

Source§

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

Folds the pair from the right (over second).

§Type Signature

forall a b t. Foldable (Pair t) => ((a, b) -> b, b, Pair t a) -> b

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

f(a, init).

§Examples
use fp_library::classes::foldable::fold_right;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;

assert_eq!(fold_right::<PairWithFirstBrand<()>, _, _, _>(|x, acc| x + acc, 0, Pair((), 5)), 5);
Source§

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

Folds the pair from the left (over second).

§Type Signature

forall a b t. Foldable (Pair t) => ((b, a) -> b, b, Pair t a) -> b

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

f(init, a).

§Examples
use fp_library::classes::foldable::fold_left;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;

assert_eq!(fold_left::<PairWithFirstBrand<()>, _, _, _>(|acc, x| acc + x, 0, Pair((), 5)), 5);
Source§

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

Maps the value to a monoid and returns it (over second).

§Type Signature

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

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

f(a).

§Examples
use fp_library::classes::foldable::fold_map;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::types::string;

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

impl<First: 'static> Functor for PairWithFirstBrand<First>

Source§

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

Maps a function over the second value in the pair.

§Type Signature

forall a b t. Functor (Pair t) => (a -> b, Pair t a) -> Pair t b

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

A new pair containing the result of applying the function to the second value.

§Examples
use fp_library::classes::functor::map;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;

assert_eq!(map::<PairWithFirstBrand<_>, _, _, _>(|x: i32| x * 2, Pair(1, 5)), Pair(1, 10));
Source§

impl<First: Hash> Hash for PairWithFirstBrand<First>

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<First: 'static> Kind1L1T for PairWithFirstBrand<First>

Source§

type Output<'a, A: 'a> = Pair<First, A>

Source§

impl<First> Lift for PairWithFirstBrand<First>
where First: Semigroup + Clone + 'static,

Source§

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

Lifts a binary function into the pair context (over second).

§Type Signature

forall a b c t. (Lift (Pair t), Semigroup t) => ((a, b) -> c, Pair t a, Pair t b) -> Pair t c

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

A new pair where the first values are combined using Semigroup::append and the second values are combined using f.

§Examples
use fp_library::classes::lift::lift2;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::types::string;

assert_eq!(
    lift2::<PairWithFirstBrand<String>, _, _, _, _>(|x, y| x + y, Pair("a".to_string(), 1), Pair("b".to_string(), 2)),
    Pair("ab".to_string(), 3)
);
Source§

impl<First: Ord> Ord for PairWithFirstBrand<First>

Source§

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

Source§

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

Source§

fn partial_cmp(&self, other: &PairWithFirstBrand<First>) -> 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<First> Pointed for PairWithFirstBrand<First>
where First: Monoid + Clone + 'static,

Source§

fn pure<'a, A: 'a>(a: A) -> Apply1L1T<'a, Self, A>

Wraps a value in a pair (with empty first).

§Type Signature

forall a t. (Pointed (Pair t), Monoid t) => a -> Pair t a

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

A pair containing the empty value of the first type and a.

§Examples
use fp_library::classes::pointed::pure;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::types::string;

assert_eq!(pure::<PairWithFirstBrand<String>, _>(5), Pair("".to_string(), 5));
Source§

impl<First> Semiapplicative for PairWithFirstBrand<First>
where First: Semigroup + Clone + 'static,

Source§

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

Applies a wrapped function to a wrapped value (over second).

§Type Signature

forall a b t. (Semiapplicative (Pair t), Semigroup t) => (Pair t (a -> b), Pair t a) -> Pair t b

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

A new pair where the first values are combined and the function is applied to the second value.

§Examples
use fp_library::classes::semiapplicative::apply;
use fp_library::classes::clonable_fn::ClonableFn;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::brands::RcFnBrand;
use fp_library::types::string;
use std::rc::Rc;

let f = Pair("a".to_string(), <RcFnBrand as ClonableFn>::new(|x: i32| x * 2));
assert_eq!(apply::<PairWithFirstBrand<String>, _, _, RcFnBrand>(f, Pair("b".to_string(), 5)), Pair("ab".to_string(), 10));
Source§

impl<First> Semimonad for PairWithFirstBrand<First>
where First: Semigroup + Clone + 'static,

Source§

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

Chains pair computations (over second).

§Type Signature

forall a b t. (Semimonad (Pair t), Semigroup t) => (Pair t a, a -> Pair t b) -> Pair t b

§Parameters
  • ma: The first pair.
  • f: The function to apply to the second value.
§Returns

A new pair where the first values are combined.

§Examples
use fp_library::classes::semimonad::bind;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::types::string;

assert_eq!(
    bind::<PairWithFirstBrand<String>, _, _, _>(Pair("a".to_string(), 5), |x| Pair("b".to_string(), x * 2)),
    Pair("ab".to_string(), 10)
);
Source§

impl<First: Clone + 'static> Traversable for PairWithFirstBrand<First>

Source§

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

Traverses the pair with an applicative function (over second).

§Type Signature

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

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

The pair wrapped in the applicative context.

§Examples
use fp_library::classes::traversable::traverse;
use fp_library::brands::{PairWithFirstBrand, OptionBrand};
use fp_library::types::Pair;

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

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

Sequences a pair of applicative (over second).

§Type Signature

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

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

The pair wrapped in the applicative context.

§Examples
use fp_library::classes::traversable::sequence;
use fp_library::brands::{PairWithFirstBrand, OptionBrand};
use fp_library::types::Pair;

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

impl<First: Copy> Copy for PairWithFirstBrand<First>

Source§

impl<First: Eq> Eq for PairWithFirstBrand<First>

Source§

impl<First> StructuralPartialEq for PairWithFirstBrand<First>

Auto Trait Implementations§

§

impl<First> Freeze for PairWithFirstBrand<First>
where First: Freeze,

§

impl<First> RefUnwindSafe for PairWithFirstBrand<First>
where First: RefUnwindSafe,

§

impl<First> Send for PairWithFirstBrand<First>
where First: Send,

§

impl<First> Sync for PairWithFirstBrand<First>
where First: Sync,

§

impl<First> Unpin for PairWithFirstBrand<First>
where First: Unpin,

§

impl<First> UnwindSafe for PairWithFirstBrand<First>
where First: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<Brand> Applicative for Brand

Source§

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