pub struct PairFirstAppliedBrand<First>(/* private fields */);Expand description
Brand for the partially-applied form of Pair with the first value applied.
Trait Implementations§
Source§impl<First: Clone + Semigroup + 'static> ApplyFirst for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: Clone + Semigroup + 'static> ApplyFirst for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
Source§fn apply_first<'a, A: 'a + Clone, B: 'a + Clone>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn apply_first<'a, A: 'a + Clone, B: 'a + Clone>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Source§impl<First: Clone + Semigroup + 'static> ApplySecond for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: Clone + Semigroup + 'static> ApplySecond for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
Source§fn apply_second<'a, A: 'a + Clone, B: 'a + Clone>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
fn apply_second<'a, A: 'a + Clone, B: 'a + Clone>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, fb: <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
Source§impl<First: Clone> Clone for PairFirstAppliedBrand<First>
impl<First: Clone> Clone for PairFirstAppliedBrand<First>
Source§fn clone(&self) -> PairFirstAppliedBrand<First>
fn clone(&self) -> PairFirstAppliedBrand<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 PairFirstAppliedBrand<First>
impl<First: Debug> Debug for PairFirstAppliedBrand<First>
Source§impl<First: Default> Default for PairFirstAppliedBrand<First>
impl<First: Default> Default for PairFirstAppliedBrand<First>
Source§fn default() -> PairFirstAppliedBrand<First>
fn default() -> PairFirstAppliedBrand<First>
Source§impl<First: 'static> Foldable for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: 'static> Foldable for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>,
) -> Bwhere
FnBrand: CloneFn + 'a,
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>,
) -> Bwhere
FnBrand: CloneFn + 'a,
Folds the pair from the right (over second).
This method performs a right-associative fold of the pair (over second).
§Type Signature
forall First A B. CloneFn FnBrand => ((A, B) -> B, B, PairFirstApplied First 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 pair to fold.
§Returns
func(a, initial).
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
explicit::fold_right::<RcFnBrand, PairFirstAppliedBrand<()>, _, _, _, _>(
|x, acc| x + acc,
0,
Pair((), 5)
),
5
);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>,
) -> Bwhere
FnBrand: CloneFn + 'a,
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>,
) -> Bwhere
FnBrand: CloneFn + 'a,
Folds the pair from the left (over second).
This method performs a left-associative fold of the pair (over second).
§Type Signature
forall First A B. CloneFn FnBrand => ((B, A) -> B, B, PairFirstApplied First 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 identity to fold.
§Returns
func(initial, a).
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
explicit::fold_left::<RcFnBrand, PairFirstAppliedBrand<()>, _, _, _, _>(
|acc, x| acc + x,
0,
Pair((), 5)
),
5
);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
fn fold_map<'a, FnBrand, A: 'a + Clone, M>( func: impl Fn(A) -> M + 'a, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
Maps the value to a monoid and returns it (over second).
This method maps the element of the pair to a monoid and then returns it (over second).
§Type Signature
forall First A M. (Monoid M, CloneFn FnBrand) => (A -> M, PairFirstApplied First 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 pair to fold.
§Returns
func(a).
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
explicit::fold_map::<RcFnBrand, PairFirstAppliedBrand<()>, _, _, _, _>(
|x: i32| x.to_string(),
Pair((), 5)
),
"5".to_string()
);Source§impl<First: 'static> Functor for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: 'static> Functor for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>
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 second value in the pair.
This method applies a function to the second value inside the pair, producing a new pair with the transformed second value. The first value remains unchanged.
§Type Signature
forall First A B. (A -> B, PairFirstApplied First A) -> PairFirstApplied First B
§Type Parameters
'a: The lifetime of the values.A: The type of the second value.B: The type of the result of applying the function.
§Parameters
func: 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::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
explicit::map::<PairFirstAppliedBrand<_>, _, _, _, _>(|x: i32| x * 2, Pair(1, 5)),
Pair(1, 10)
);Source§impl<First: Hash> Hash for PairFirstAppliedBrand<First>
impl<First: Hash> Hash for PairFirstAppliedBrand<First>
Source§impl<'a, A: 'a, First: 'static> InferableBrand_cdc7cd43dac7585f<'a, PairFirstAppliedBrand<First>, A> for Pair<First, A>
Generated InferableBrand_cdc7cd43dac7585f implementation for Pair < First, A > with brand PairFirstAppliedBrand < First >.
impl<'a, A: 'a, First: 'static> InferableBrand_cdc7cd43dac7585f<'a, PairFirstAppliedBrand<First>, A> for Pair<First, A>
Generated InferableBrand_cdc7cd43dac7585f implementation for Pair < First, A > with brand PairFirstAppliedBrand < First >.
Source§impl<First: 'static> Kind_cdc7cd43dac7585f for PairFirstAppliedBrand<First>
Generated implementation of Kind_cdc7cd43dac7585f for PairFirstAppliedBrand < First >.
impl<First: 'static> Kind_cdc7cd43dac7585f for PairFirstAppliedBrand<First>
Generated implementation of Kind_cdc7cd43dac7585f for PairFirstAppliedBrand < First >.
§Type Parameters
First: The type of the first value in the pair.
Source§impl<First> Lift for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First> Lift for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>
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>
Lifts a binary function into the pair context (over second).
This method lifts a binary function to operate on the second values within the pair context. The first values are combined using their Semigroup implementation.
§Type Signature
forall First A B C. Semigroup First => ((A, B) -> C, PairFirstApplied First A, PairFirstApplied First B) -> PairFirstApplied First C
§Type Parameters
'a: The lifetime of the values.A: The type of the first second value.B: The type of the second second value.C: The type of the result second value.
§Parameters
func: 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::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
explicit::lift2::<PairFirstAppliedBrand<String>, _, _, _, _, _, _>(
|x, y| x + y,
Pair("a".to_string(), 1),
Pair("b".to_string(), 2)
),
Pair("ab".to_string(), 3)
);Source§impl<First> MonadRec for PairFirstAppliedBrand<First>
MonadRec implementation for PairFirstAppliedBrand.
impl<First> MonadRec for PairFirstAppliedBrand<First>
MonadRec implementation for PairFirstAppliedBrand.
§Type Parameters
First: The type of the first value in the pair.
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>
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 the second value, accumulating the first.
Iteratively applies the step function. Each iteration produces a pair
whose first value is combined with the running accumulator via
Semigroup::append. If the step returns ControlFlow::Continue(a), the loop
continues with the new state. If it returns ControlFlow::Break(b), the
computation completes with the accumulated first value and b.
§Type Signature
forall First A B. Monoid First => (A -> PairFirstApplied First (ControlFlow B A), A) -> PairFirstApplied First 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
A pair with the accumulated first value and the final result.
§Examples
use {
core::ops::ControlFlow,
fp_library::{
brands::*,
functions::*,
types::*,
},
};
let result = tail_rec_m::<PairFirstAppliedBrand<String>, _, _>(
|n| {
if n < 3 {
Pair(format!("{n},"), ControlFlow::Continue(n + 1))
} else {
Pair(format!("{n}"), ControlFlow::Break(n))
}
},
0,
);
assert_eq!(result, Pair("0,1,2,3".to_string(), 3));Source§impl<First: Ord> Ord for PairFirstAppliedBrand<First>
impl<First: Ord> Ord for PairFirstAppliedBrand<First>
Source§fn cmp(&self, other: &PairFirstAppliedBrand<First>) -> Ordering
fn cmp(&self, other: &PairFirstAppliedBrand<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 PairFirstAppliedBrand<First>
impl<First: PartialEq> PartialEq for PairFirstAppliedBrand<First>
Source§fn eq(&self, other: &PairFirstAppliedBrand<First>) -> bool
fn eq(&self, other: &PairFirstAppliedBrand<First>) -> bool
self and other values to be equal, and is used by ==.Source§impl<First: PartialOrd> PartialOrd for PairFirstAppliedBrand<First>
impl<First: PartialOrd> PartialOrd for PairFirstAppliedBrand<First>
Source§impl<First> Pointed for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First> Pointed for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
Source§fn pure<'a, A: 'a>(a: A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn pure<'a, A: 'a>(a: A) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Wraps a value in a pair (with empty first).
This method wraps a value in a pair, using the Monoid::empty() value for the first element.
§Type Signature
forall First A. Monoid First => A -> PairFirstApplied First A
§Type Parameters
'a: The lifetime of the value.A: The type of the value to wrap.
§Parameters
a: The value to wrap.
§Returns
A pair containing the empty value of the first type and a.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
assert_eq!(pure::<PairFirstAppliedBrand<String>, _>(5), Pair("".to_string(), 5));Source§impl<First: Clone + 'static> RefFoldable for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: Clone + 'static> RefFoldable for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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
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
Folds the pair by reference (over second).
§Type Signature
forall First A M. Monoid M => (&A -> M, &PairFirstApplied First 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 pair.
§Returns
The monoid value.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let result = explicit::fold_map::<RcFnBrand, PairFirstAppliedBrand<()>, _, _, _, _>(
|x: &i32| x.to_string(),
&Pair((), 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>,
) -> Bwhere
FnBrand: LiftFn + 'a,
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>,
) -> Bwhere
FnBrand: LiftFn + 'a,
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>,
) -> Bwhere
FnBrand: LiftFn + 'a,
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>,
) -> Bwhere
FnBrand: LiftFn + 'a,
Source§impl<First: Clone + 'static> RefFunctor for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: Clone + 'static> RefFunctor for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>
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 second value in the pair by reference.
§Type Signature
forall First A B. (&A -> B, &PairFirstApplied First A) -> PairFirstApplied First B
§Type Parameters
'a: The lifetime.A: The input type.B: The output type.
§Parameters
func: The function.fa: The pair.
§Returns
A new pair with the mapped second value.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
explicit::map::<PairFirstAppliedBrand<_>, _, _, _, _>(|x: &i32| *x * 2, &Pair(1, 5)),
Pair(1, 10)
);Source§impl<First> RefLift for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First> RefLift for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>
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 pairs with a by-reference binary function (over second).
§Type Signature
forall First A B C. Semigroup First => ((&A, &B) -> C, &PairFirstApplied First A, &PairFirstApplied First B) -> PairFirstApplied First C
§Type Parameters
'a: The lifetime.A: First input.B: Second input.C: Output.
§Parameters
func: The binary function.fa: The first pair.fb: The second pair.
§Returns
A pair with combined first values and the function result.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let result = explicit::lift2::<PairFirstAppliedBrand<String>, _, _, _, _, _, _>(
|a: &i32, b: &i32| *a + *b,
&Pair("a".to_string(), 1),
&Pair("b".to_string(), 2),
);
assert_eq!(result, Pair("ab".to_string(), 3));Source§impl<First> RefPointed for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First> RefPointed for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
Source§fn ref_pure<'a, A: Clone + 'a>(
a: &A,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn ref_pure<'a, A: Clone + 'a>( a: &A, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Creates a pair from a reference by cloning (with empty first).
§Type Signature
forall First A. Monoid First => &A -> PairFirstApplied First A
§Type Parameters
'a: The lifetime.A: The value type.
§Parameters
a: The reference to wrap.
§Returns
A pair containing Monoid::empty() and a clone of the value.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let x = 42;
let result: Pair<String, i32> = ref_pure::<PairFirstAppliedBrand<String>, _>(&x);
assert_eq!(result, Pair("".to_string(), 42));Source§impl<First> RefSemiapplicative for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First> RefSemiapplicative for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>
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 a pair value (over second).
§Type Signature
forall First A B. (CloneFn FnBrand, Semigroup First) => (&PairFirstApplied First (FnBrand A B), &PairFirstApplied First A) -> PairFirstApplied First B
§Type Parameters
'a: The lifetime.FnBrand: The function brand.A: The input type.B: The output type.
§Parameters
ff: The pair containing the function.fa: The pair containing the value.
§Returns
A pair with combined first values and the function result.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let f: std::rc::Rc<dyn Fn(&i32) -> i32> = std::rc::Rc::new(|x: &i32| *x * 2);
let result = ref_apply::<RcFnBrand, PairFirstAppliedBrand<String>, _, _>(
&Pair("a".to_string(), f),
&Pair("b".to_string(), 5),
);
assert_eq!(result, Pair("ab".to_string(), 10));Source§impl<First> RefSemimonad for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First> RefSemimonad for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>
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 pair computations by reference (over second).
§Type Signature
forall First A B. Semigroup First => (&PairFirstApplied First A, &A -> PairFirstApplied First B) -> PairFirstApplied First B
§Type Parameters
'a: The lifetime.A: The input type.B: The output type.
§Parameters
fa: The input pair.f: The function to apply by reference.
§Returns
A pair with combined first values.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let result: Pair<String, String> = explicit::bind::<PairFirstAppliedBrand<String>, _, _, _, _>(
&Pair("a".to_string(), 42),
|x: &i32| Pair("b".to_string(), x.to_string()),
);
assert_eq!(result, Pair("ab".to_string(), "42".to_string()));Source§impl<First: Clone + 'static> RefTraversable for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: Clone + 'static> RefTraversable for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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,
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 pair by reference (over second).
§Type Signature
forall First A B F. Applicative F => (&A -> F B, &PairFirstApplied First A) -> F (PairFirstApplied First 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 pair.
§Returns
The traversed result.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
let result: Option<Pair<(), String>> =
ref_traverse::<PairFirstAppliedBrand<()>, RcFnBrand, _, _, OptionBrand>(
|x: &i32| Some(x.to_string()),
&Pair((), 42),
);
assert_eq!(result, Some(Pair((), "42".to_string())));Source§impl<First> Semiapplicative for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First> Semiapplicative for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>
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 (over second).
This method applies a function wrapped in a pair to a value wrapped in a pair. The first values are combined using their Semigroup implementation.
§Type Signature
forall First A B. (CloneFn FnBrand, Semigroup First) => (PairFirstApplied First (FnBrand A B), PairFirstApplied First A) -> PairFirstApplied First 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 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::{
brands::*,
classes::semiapplicative::apply as explicit_apply,
functions::*,
types::*,
};
let f = Pair("a".to_string(), lift_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2));
assert_eq!(
explicit_apply::<RcFnBrand, PairFirstAppliedBrand<String>, _, _>(
f,
Pair("b".to_string(), 5)
),
Pair("ab".to_string(), 10)
);Source§impl<First> Semimonad for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First> Semimonad for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>
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 pair computations (over second).
This method chains two computations, where the second computation depends on the result of the first. The first values are combined using their Semigroup implementation.
§Type Signature
forall First A B. Semigroup First => (PairFirstApplied First A, A -> PairFirstApplied First B) -> PairFirstApplied First 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 pair.func: The function to apply to the second value.
§Returns
A new pair where the first values are combined.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
explicit::bind::<PairFirstAppliedBrand<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 PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
impl<First: Clone + 'static> Traversable for PairFirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the pair.
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>>
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>>
Traverses the pair with an applicative function (over second).
This method maps the element of the pair to a computation, evaluates it, and combines the result into an applicative context (over second).
§Type Signature
forall First A B F. Applicative F => (A -> F B, PairFirstApplied First A) -> F (PairFirstApplied First 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 pair to traverse.
§Returns
The pair wrapped in the applicative context.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
explicit::traverse::<RcFnBrand, PairFirstAppliedBrand<()>, _, _, OptionBrand, _, _>(
|x| Some(x * 2),
Pair((), 5)
),
Some(Pair((), 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,
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 a pair of applicative (over second).
This method evaluates the computation inside the pair and accumulates the result into an applicative context (over second).
§Type Signature
forall First A F. Applicative F => PairFirstApplied First (F A) -> F (PairFirstApplied First 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 pair containing the applicative value.
§Returns
The pair wrapped in the applicative context.
§Examples
use fp_library::{
brands::*,
functions::*,
types::*,
};
assert_eq!(
sequence::<PairFirstAppliedBrand<()>, _, OptionBrand>(Pair((), Some(5))),
Some(Pair((), 5))
);impl<First: Copy> Copy for PairFirstAppliedBrand<First>
impl<First: Eq> Eq for PairFirstAppliedBrand<First>
impl<First> StructuralPartialEq for PairFirstAppliedBrand<First>
Auto Trait Implementations§
impl<First> Freeze for PairFirstAppliedBrand<First>
impl<First> RefUnwindSafe for PairFirstAppliedBrand<First>where
First: RefUnwindSafe,
impl<First> Send for PairFirstAppliedBrand<First>where
First: Send,
impl<First> Sync for PairFirstAppliedBrand<First>where
First: Sync,
impl<First> Unpin for PairFirstAppliedBrand<First>where
First: Unpin,
impl<First> UnsafeUnpin for PairFirstAppliedBrand<First>
impl<First> UnwindSafe for PairFirstAppliedBrand<First>where
First: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more