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>
impl<First: Clone + Semigroup + 'static> ApplyFirst for PairWithFirstBrand<First>
Source§impl<First: Clone + Semigroup + 'static> ApplySecond for PairWithFirstBrand<First>
impl<First: Clone + Semigroup + 'static> ApplySecond for PairWithFirstBrand<First>
Source§impl<First: Clone> Clone for PairWithFirstBrand<First>
impl<First: Clone> Clone for PairWithFirstBrand<First>
Source§fn clone(&self) -> PairWithFirstBrand<First>
fn clone(&self) -> PairWithFirstBrand<First>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<First: Debug> Debug for PairWithFirstBrand<First>
impl<First: Debug> Debug for PairWithFirstBrand<First>
Source§impl<First: Default> Default for PairWithFirstBrand<First>
impl<First: Default> Default for PairWithFirstBrand<First>
Source§fn default() -> PairWithFirstBrand<First>
fn default() -> PairWithFirstBrand<First>
Source§impl<First: 'static> Foldable for PairWithFirstBrand<First>
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>,
) -> Bwhere
F: Fn(A, B) -> B + 'a,
fn fold_right<'a, A: 'a, B: 'a, F>(
f: F,
init: B,
fa: Apply1L1T<'a, Self, A>,
) -> Bwhere
F: Fn(A, B) -> B + 'a,
Folds the 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>,
) -> Bwhere
F: Fn(B, A) -> B + 'a,
fn fold_left<'a, A: 'a, B: 'a, F>(
f: F,
init: B,
fa: Apply1L1T<'a, Self, A>,
) -> Bwhere
F: Fn(B, A) -> B + 'a,
Folds the 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
fn fold_map<'a, A: 'a, M, F>(f: F, fa: Apply1L1T<'a, Self, A>) -> M
Maps the value to a monoid and returns it (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>
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,
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>
impl<First: Hash> Hash for PairWithFirstBrand<First>
Source§impl<First: 'static> Kind1L1T for PairWithFirstBrand<First>
impl<First: 'static> Kind1L1T for PairWithFirstBrand<First>
Source§impl<First> Lift for PairWithFirstBrand<First>
impl<First> Lift for PairWithFirstBrand<First>
Source§fn lift2<'a, A, B, C, F>(
f: F,
fa: Apply1L1T<'a, Self, A>,
fb: Apply1L1T<'a, Self, B>,
) -> Apply1L1T<'a, Self, C>
fn lift2<'a, A, B, C, F>( f: F, fa: Apply1L1T<'a, Self, A>, fb: Apply1L1T<'a, Self, B>, ) -> Apply1L1T<'a, Self, C>
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>
impl<First: Ord> Ord for PairWithFirstBrand<First>
Source§fn cmp(&self, other: &PairWithFirstBrand<First>) -> Ordering
fn cmp(&self, other: &PairWithFirstBrand<First>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<First: PartialEq> PartialEq for PairWithFirstBrand<First>
impl<First: PartialEq> PartialEq for PairWithFirstBrand<First>
Source§impl<First: PartialOrd> PartialOrd for PairWithFirstBrand<First>
impl<First: PartialOrd> PartialOrd for PairWithFirstBrand<First>
Source§impl<First> Pointed for PairWithFirstBrand<First>
impl<First> Pointed for PairWithFirstBrand<First>
Source§fn pure<'a, A: 'a>(a: A) -> Apply1L1T<'a, Self, A>
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>
impl<First> Semiapplicative for PairWithFirstBrand<First>
Source§fn apply<'a, A: 'a + Clone, B: 'a, FnBrand: 'a + ClonableFn>(
ff: Apply1L1T<'a, Self, ApplyClonableFn<'a, FnBrand, A, B>>,
fa: Apply1L1T<'a, Self, A>,
) -> Apply1L1T<'a, Self, B>
fn apply<'a, A: 'a + Clone, B: 'a, FnBrand: 'a + ClonableFn>( ff: Apply1L1T<'a, Self, ApplyClonableFn<'a, FnBrand, A, B>>, fa: Apply1L1T<'a, Self, A>, ) -> Apply1L1T<'a, Self, B>
Applies a wrapped function to a wrapped value (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>
impl<First> Semimonad for PairWithFirstBrand<First>
Source§fn bind<'a, A: 'a, B: 'a, F>(
ma: Apply1L1T<'a, Self, A>,
f: F,
) -> Apply1L1T<'a, Self, B>
fn bind<'a, A: 'a, B: 'a, F>( ma: Apply1L1T<'a, Self, A>, f: F, ) -> Apply1L1T<'a, Self, B>
Chains 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>
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>>
fn traverse<'a, F: Applicative, A: 'a + Clone, B: 'a + Clone, Func>( f: Func, ta: Apply1L1T<'a, Self, A>, ) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, B>>
Traverses the 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>>
fn sequence<'a, F: Applicative, A: 'a + Clone>( ta: Apply1L1T<'a, Self, Apply1L1T<'a, F, A>>, ) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, A>>
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))
);