Skip to main content

PairFirstAppliedBrand

Struct PairFirstAppliedBrand 

Source
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.
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<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>

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

impl<First: Clone> Clone for PairFirstAppliedBrand<First>

Source§

fn clone(&self) -> PairFirstAppliedBrand<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 PairFirstAppliedBrand<First>

Source§

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

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

impl<First: Default> Default for PairFirstAppliedBrand<First>

Source§

fn default() -> PairFirstAppliedBrand<First>

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

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>, ) -> B
where 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>, ) -> B
where 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
where M: Monoid + 'a, FnBrand: CloneFn + 'a,

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.
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 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>

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<'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§

type Marker = Val

Dispatch marker: Val for owned types, Ref for references.
Source§

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§

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

The applied type.
Source§

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

§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>
where A: Clone + 'a, B: Clone + 'a, C: 'a,

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>
where First: Monoid + Clone + 'static,

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>

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>

Source§

fn cmp(&self, other: &PairFirstAppliedBrand<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 PairFirstAppliedBrand<First>

Source§

fn eq(&self, other: &PairFirstAppliedBrand<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 PairFirstAppliedBrand<First>

Source§

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

§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>

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.
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 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>, ) -> 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<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>

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>
where First: Semigroup + Clone + 'static,

§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>

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>
where First: Monoid + Clone + 'static,

§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>

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>
where First: Semigroup + Clone + 'static,

§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>

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>
where First: Semigroup + Clone + 'static,

§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>

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.
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 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>
where First: Semigroup + Clone + 'static,

§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>

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>
where First: Semigroup + Clone + 'static,

§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>

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.
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 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,

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))
);
Source§

impl<First: Copy> Copy for PairFirstAppliedBrand<First>

Source§

impl<First: Eq> Eq for PairFirstAppliedBrand<First>

Source§

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> 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> Applicative for Brand

Source§

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

Source§

impl<Brand> RefApplicative for Brand

Source§

impl<Brand> RefMonad for Brand