pub struct Tuple2FirstAppliedBrand<First>(/* private fields */);Expand description
Brand for (First, Second), with First applied (Functor over Second).
Trait Implementations§
Source§impl<First: Clone + Semigroup + 'static> ApplyFirst for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First: Clone + Semigroup + 'static> ApplyFirst for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First: Clone + Semigroup + 'static> ApplySecond for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 Tuple2FirstAppliedBrand<First>
impl<First: Clone> Clone for Tuple2FirstAppliedBrand<First>
Source§fn clone(&self) -> Tuple2FirstAppliedBrand<First>
fn clone(&self) -> Tuple2FirstAppliedBrand<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 Tuple2FirstAppliedBrand<First>
impl<First: Debug> Debug for Tuple2FirstAppliedBrand<First>
Source§impl<First: Default> Default for Tuple2FirstAppliedBrand<First>
impl<First: Default> Default for Tuple2FirstAppliedBrand<First>
Source§fn default() -> Tuple2FirstAppliedBrand<First>
fn default() -> Tuple2FirstAppliedBrand<First>
Source§impl<First: 'static> Foldable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First: 'static> Foldable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple from the right (over second).
This method performs a right-associative fold of the tuple (over second).
§Type Signature
forall First A B. CloneFn FnBrand => ((A, B) -> B, B, Tuple2FirstApplied 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 tuple to fold.
§Returns
func(a, initial).
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
explicit::fold_right::<RcFnBrand, Tuple2FirstAppliedBrand<()>, _, _, _, _>(
|x, acc| x + acc,
0,
((), 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 tuple from the left (over second).
This method performs a left-associative fold of the tuple (over second).
§Type Signature
forall First A B. CloneFn FnBrand => ((B, A) -> B, B, Tuple2FirstApplied 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 tuple to fold.
§Returns
func(initial, a).
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
explicit::fold_left::<RcFnBrand, Tuple2FirstAppliedBrand<()>, _, _, _, _>(
|acc, x| acc + x,
0,
((), 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 tuple to a monoid and then returns it (over second).
§Type Signature
forall First A M. (Monoid M, CloneFn FnBrand) => (A -> M, Tuple2FirstApplied 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 tuple to fold.
§Returns
func(a).
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
explicit::fold_map::<RcFnBrand, Tuple2FirstAppliedBrand<()>, _, _, _, _>(
|x: i32| x.to_string(),
((), 5)
),
"5".to_string()
);Source§impl<First: 'static> Functor for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First: 'static> Functor for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple.
This method applies a function to the second value inside the tuple, producing a new tuple with the transformed second value. The first value remains unchanged.
§Type Signature
forall First A B. (A -> B, Tuple2FirstApplied First A) -> Tuple2FirstApplied 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 tuple to map over.
§Returns
A new tuple containing the result of applying the function to the second value.
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
explicit::map::<Tuple2FirstAppliedBrand<_>, _, _, _, _>(|x: i32| x * 2, (1, 5)),
(1, 10)
);Source§impl<First: Hash> Hash for Tuple2FirstAppliedBrand<First>
impl<First: Hash> Hash for Tuple2FirstAppliedBrand<First>
Source§impl<'a, A: 'a, First: 'static> InferableBrand_cdc7cd43dac7585f<'a, Tuple2FirstAppliedBrand<First>, A> for (First, A)
Generated InferableBrand_cdc7cd43dac7585f implementation for (First, A) with brand Tuple2FirstAppliedBrand < First >.
impl<'a, A: 'a, First: 'static> InferableBrand_cdc7cd43dac7585f<'a, Tuple2FirstAppliedBrand<First>, A> for (First, A)
Generated InferableBrand_cdc7cd43dac7585f implementation for (First, A) with brand Tuple2FirstAppliedBrand < First >.
Source§impl<First: 'static> Kind_cdc7cd43dac7585f for Tuple2FirstAppliedBrand<First>
Generated implementation of Kind_cdc7cd43dac7585f for Tuple2FirstAppliedBrand < First >.
impl<First: 'static> Kind_cdc7cd43dac7585f for Tuple2FirstAppliedBrand<First>
Generated implementation of Kind_cdc7cd43dac7585f for Tuple2FirstAppliedBrand < First >.
Source§type Of<'a, A: 'a> = (First, A)
type Of<'a, A: 'a> = (First, A)
Source§impl<First> Lift for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> Lift for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple context (over second).
This method lifts a binary function to operate on the second values within the tuple context. The first values are combined using their Semigroup implementation.
§Type Signature
forall First A B C. Semigroup First => ((A, B) -> C, Tuple2FirstApplied First A, Tuple2FirstApplied First B) -> Tuple2FirstApplied 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 tuple.fb: The second tuple.
§Returns
A new tuple where the first values are combined using Semigroup::append and the second values are combined using f.
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
explicit::lift2::<Tuple2FirstAppliedBrand<String>, _, _, _, _, _, _>(
|x, y| x + y,
("a".to_string(), 1),
("b".to_string(), 2)
),
("ab".to_string(), 3)
);Source§impl<First> MonadRec for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> MonadRec for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 a tuple (varying the second element).
Iteratively applies the step function, accumulating the first element
via Semigroup::append at each iteration. When the step function returns
ControlFlow::Break, the accumulated first element and the final result are returned.
§Type Signature
forall First A B. Monoid First => (A -> Tuple2FirstApplied First (ControlFlow B A), A) -> Tuple2FirstApplied 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 tuple with the accumulated first value and the result of the computation.
§Examples
use {
core::ops::ControlFlow,
fp_library::{
brands::*,
functions::*,
types::*,
},
};
let result = tail_rec_m::<Tuple2FirstAppliedBrand<String>, _, _>(
|n| {
if n < 3 {
(format!("{n},"), ControlFlow::Continue(n + 1))
} else {
(format!("{n}"), ControlFlow::Break(n))
}
},
0,
);
assert_eq!(result, ("0,1,2,3".to_string(), 3));Source§impl<First: Ord> Ord for Tuple2FirstAppliedBrand<First>
impl<First: Ord> Ord for Tuple2FirstAppliedBrand<First>
Source§fn cmp(&self, other: &Tuple2FirstAppliedBrand<First>) -> Ordering
fn cmp(&self, other: &Tuple2FirstAppliedBrand<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 Tuple2FirstAppliedBrand<First>
impl<First: PartialEq> PartialEq for Tuple2FirstAppliedBrand<First>
Source§fn eq(&self, other: &Tuple2FirstAppliedBrand<First>) -> bool
fn eq(&self, other: &Tuple2FirstAppliedBrand<First>) -> bool
self and other values to be equal, and is used by ==.Source§impl<First: PartialOrd> PartialOrd for Tuple2FirstAppliedBrand<First>
impl<First: PartialOrd> PartialOrd for Tuple2FirstAppliedBrand<First>
Source§impl<First> Pointed for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> Pointed for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple (with empty first).
This method wraps a value in a tuple, using the Monoid::empty() value for the first element.
§Type Signature
forall First A. Monoid First => A -> Tuple2FirstApplied 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 tuple containing the empty value of the first type and a.
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(pure::<Tuple2FirstAppliedBrand<String>, _>(5), ("".to_string(), 5));Source§impl<First: Clone + 'static> RefFoldable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First: Clone + 'static> RefFoldable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple by reference (over second).
§Type Signature
forall First A M. Monoid M => (&A -> M, &Tuple2FirstApplied 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 tuple.
§Returns
The monoid value.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let result = explicit::fold_map::<RcFnBrand, Tuple2FirstAppliedBrand<()>, _, _, _, _>(
|x: &i32| x.to_string(),
&((), 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 Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First: Clone + 'static> RefFunctor for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple by reference.
§Type Signature
forall First A B. (&A -> B, &Tuple2FirstApplied First A) -> Tuple2FirstApplied First B
§Type Parameters
'a: The lifetime.A: The input type.B: The output type.
§Parameters
func: The function.fa: The tuple.
§Returns
A new tuple with the mapped second value.
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
explicit::map::<Tuple2FirstAppliedBrand<_>, _, _, _, _>(|x: &i32| *x * 2, &(1, 5)),
(1, 10)
);Source§impl<First> RefLift for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> RefLift for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuples with a by-reference binary function (over second).
§Type Signature
forall First A B C. Semigroup First => ((&A, &B) -> C, &Tuple2FirstApplied First A, &Tuple2FirstApplied First B) -> Tuple2FirstApplied First C
§Type Parameters
'a: The lifetime.A: First input.B: Second input.C: Output.
§Parameters
func: The binary function.fa: The first tuple.fb: The second tuple.
§Returns
A tuple with combined first values and the function result.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let result = explicit::lift2::<Tuple2FirstAppliedBrand<String>, _, _, _, _, _, _>(
|a: &i32, b: &i32| *a + *b,
&("a".to_string(), 1),
&("b".to_string(), 2),
);
assert_eq!(result, ("ab".to_string(), 3));Source§impl<First> RefPointed for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> RefPointed for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple from a reference by cloning (with empty first).
§Type Signature
forall First A. Monoid First => &A -> Tuple2FirstApplied First A
§Type Parameters
'a: The lifetime.A: The value type.
§Parameters
a: The reference to wrap.
§Returns
A tuple containing Monoid::empty() and a clone of the value.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let x = 42;
let result: (String, i32) = ref_pure::<Tuple2FirstAppliedBrand<String>, _>(&x);
assert_eq!(result, ("".to_string(), 42));Source§impl<First> RefSemiapplicative for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> RefSemiapplicative for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple value (over second).
§Type Signature
forall First A B. (CloneFn FnBrand, Semigroup First) => (&Tuple2FirstApplied First (FnBrand A B), &Tuple2FirstApplied First A) -> Tuple2FirstApplied First B
§Type Parameters
'a: The lifetime.FnBrand: The function brand.A: The input type.B: The output type.
§Parameters
ff: The tuple containing the function.fa: The tuple containing the value.
§Returns
A tuple with combined first values and the function result.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let f: std::rc::Rc<dyn Fn(&i32) -> i32> = std::rc::Rc::new(|x: &i32| *x * 2);
let result = ref_apply::<RcFnBrand, Tuple2FirstAppliedBrand<String>, _, _>(
&("a".to_string(), f),
&("b".to_string(), 5),
);
assert_eq!(result, ("ab".to_string(), 10));Source§impl<First> RefSemimonad for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> RefSemimonad for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple computations by reference (over second).
§Type Signature
forall First A B. Semigroup First => (&Tuple2FirstApplied First A, &A -> Tuple2FirstApplied First B) -> Tuple2FirstApplied First B
§Type Parameters
'a: The lifetime.A: The input type.B: The output type.
§Parameters
fa: The input tuple.f: The function to apply by reference.
§Returns
A tuple with combined first values.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let result: (String, String) = explicit::bind::<Tuple2FirstAppliedBrand<String>, _, _, _, _>(
&("a".to_string(), 42),
|x: &i32| ("b".to_string(), x.to_string()),
);
assert_eq!(result, ("ab".to_string(), "42".to_string()));Source§impl<First: Clone + 'static> RefTraversable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First: Clone + 'static> RefTraversable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple by reference (over second).
§Type Signature
forall First A B F. Applicative F => (&A -> F B, &Tuple2FirstApplied First A) -> F (Tuple2FirstApplied 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 tuple.
§Returns
The traversed result.
§Examples
use fp_library::{
brands::*,
functions::*,
};
let result: Option<((), String)> =
ref_traverse::<Tuple2FirstAppliedBrand<()>, RcFnBrand, _, _, OptionBrand>(
|x: &i32| Some(x.to_string()),
&((), 42),
);
assert_eq!(result, Some(((), "42".to_string())));Source§impl<First> Semiapplicative for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> Semiapplicative for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple to a value wrapped in a tuple. The first values are combined using their Semigroup implementation.
§Type Signature
forall First A B. (CloneFn FnBrand, Semigroup First) => (Tuple2FirstApplied First (FnBrand A B), Tuple2FirstApplied First A) -> Tuple2FirstApplied 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 tuple containing the function.fa: The tuple containing the value.
§Returns
A new tuple 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::*,
};
let f = ("a".to_string(), lift_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2));
assert_eq!(
explicit_apply::<RcFnBrand, Tuple2FirstAppliedBrand<String>, _, _>(f, ("b".to_string(), 5)),
("ab".to_string(), 10)
);Source§impl<First> Semimonad for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First> Semimonad for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple 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 => (Tuple2FirstApplied First A, A -> Tuple2FirstApplied First B) -> Tuple2FirstApplied 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 tuple.func: The function to apply to the second value.
§Returns
A new tuple where the first values are combined.
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
explicit::bind::<Tuple2FirstAppliedBrand<String>, _, _, _, _>(("a".to_string(), 5), |x| (
"b".to_string(),
x * 2
)),
("ab".to_string(), 10)
);Source§impl<First: Clone + 'static> Traversable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
impl<First: Clone + 'static> Traversable for Tuple2FirstAppliedBrand<First>
§Type Parameters
First: The type of the first value in the tuple.
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 tuple with an applicative function (over second).
This method maps the element of the tuple 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, Tuple2FirstApplied First A) -> F (Tuple2FirstApplied 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 tuple to traverse.
§Returns
The tuple wrapped in the applicative context.
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
explicit::traverse::<RcFnBrand, Tuple2FirstAppliedBrand<()>, _, _, OptionBrand, _, _>(
|x| Some(x * 2),
((), 5)
),
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,
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 tuple of applicative (over second).
This method evaluates the computation inside the tuple and accumulates the result into an applicative context (over second).
§Type Signature
forall First A F. Applicative F => Tuple2FirstApplied First (F A) -> F (Tuple2FirstApplied 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 tuple containing the applicative value.
§Returns
The tuple wrapped in the applicative context.
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(
sequence::<Tuple2FirstAppliedBrand<()>, _, OptionBrand>(((), Some(5))),
Some(((), 5))
);impl<First: Copy> Copy for Tuple2FirstAppliedBrand<First>
impl<First: Eq> Eq for Tuple2FirstAppliedBrand<First>
impl<First> StructuralPartialEq for Tuple2FirstAppliedBrand<First>
Auto Trait Implementations§
impl<First> Freeze for Tuple2FirstAppliedBrand<First>
impl<First> RefUnwindSafe for Tuple2FirstAppliedBrand<First>where
First: RefUnwindSafe,
impl<First> Send for Tuple2FirstAppliedBrand<First>where
First: Send,
impl<First> Sync for Tuple2FirstAppliedBrand<First>where
First: Sync,
impl<First> Unpin for Tuple2FirstAppliedBrand<First>where
First: Unpin,
impl<First> UnsafeUnpin for Tuple2FirstAppliedBrand<First>
impl<First> UnwindSafe for Tuple2FirstAppliedBrand<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