PairWithFirstBrand

Struct PairWithFirstBrand 

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

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

Trait Implementations§

Source§

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

Source§

fn apply_first<'a, A: 'a + Clone, B: 'a + Clone>( fa: <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 PairWithFirstBrand<First>

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 PairWithFirstBrand<First>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<First: Debug> Debug for PairWithFirstBrand<First>

Source§

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

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

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

Source§

fn default() -> PairWithFirstBrand<First>

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

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

Source§

fn fold_right<'a, FnBrand, Func, A: 'a, B: 'a>( func: Func, initial: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where Func: Fn(A, B) -> B + 'a, FnBrand: ClonableFn + 'a,

Folds the pair from the right (over second).

This method performs a right-associative fold of the pair (over second).

§Type Signature

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

§Type Parameters
  • FnBrand: The brand of the clonable function to use.
  • Func: The type of the folding function.
  • 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::classes::foldable::fold_right;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::brands::RcFnBrand;

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

fn fold_left<'a, FnBrand, Func, A: 'a, B: 'a>( func: Func, initial: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where Func: Fn(B, A) -> B + 'a, FnBrand: ClonableFn + 'a,

Folds the pair from the left (over second).

This method performs a left-associative fold of the pair (over second).

§Type Signature

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

§Type Parameters
  • FnBrand: The brand of the clonable function to use.
  • Func: The type of the folding function.
  • 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 pair to fold.
§Returns

func(initial, a).

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

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

fn fold_map<'a, FnBrand, Func, A: 'a, M>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
where M: Monoid + 'a, Func: Fn(A) -> M + 'a, FnBrand: ClonableFn + '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 a m t. (Foldable (Pair t), Monoid m) => ((a) -> m, Pair t a) -> m

§Type Parameters
  • FnBrand: The brand of the clonable function to use.
  • Func: The type of the mapping function.
  • 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::classes::foldable::fold_map;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::types::string;
use fp_library::brands::RcFnBrand;

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

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

Source§

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

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 a b t. Functor (Pair t) => (a -> b, Pair t a) -> Pair t b

§Type Parameters
  • F: The type of the function to apply.
  • A: The type of the second value.
  • B: The type of the result of applying the function.
§Parameters
  • f: The function to apply to the second value.
  • fa: The pair to map over.
§Returns

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

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

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

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

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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

Generated implementation of Kind_cdc7cd43dac7585f for PairWithFirstBrand < First >.

Source§

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

Source§

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

Source§

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

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

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 a b c t. (Lift (Pair t), Semigroup t) => ((a, b) -> c, Pair t a, Pair t b) -> Pair t c

§Type Parameters
  • F: The type of the binary function.
  • 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
  • f: The binary function to apply to the second values.
  • fa: The first pair.
  • fb: The second pair.
§Returns

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

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

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

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

Source§

fn cmp(&self, other: &PairWithFirstBrand<First>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<First: 'static, FnBrand: SendClonableFn> ParFoldable<FnBrand> for PairWithFirstBrand<First>

Source§

fn par_fold_map<'a, A, M>( func: <FnBrand as SendClonableFn>::SendOf<'a, A, M>, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> M
where A: 'a + Clone + Send + Sync, M: Monoid + Send + Sync + 'a,

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

This method maps the element of the pair to a monoid and then returns it (over second). The mapping operation may be executed in parallel.

§Type Signature

forall a m t. (ParFoldable (Pair t), Monoid m, Send m, Sync m) => (f a m, Pair t a) -> m

§Type Parameters
  • FnBrand: The brand of thread-safe function to use (must implement SendClonableFn).
  • A: The element type (must be Send + Sync).
  • M: The monoid type (must be Send + Sync).
§Parameters
  • func: The thread-safe function to map each element to a monoid.
  • fa: The pair to fold.
§Returns

The combined monoid value.

§Examples
use fp_library::classes::par_foldable::par_fold_map;
use fp_library::brands::{PairWithFirstBrand, ArcFnBrand};
use fp_library::classes::send_clonable_fn::SendClonableFn;
use fp_library::types::{Pair, string};

let x = Pair("a".to_string(), 1);
let f = <ArcFnBrand as SendClonableFn>::new_send(|x: i32| x.to_string());
assert_eq!(
    par_fold_map::<ArcFnBrand, PairWithFirstBrand<String>, _, _>(f, x),
    "1".to_string()
);
Source§

fn par_fold_right<'a, A, B>( func: <FnBrand as SendClonableFn>::SendOf<'a, (A, B), B>, initial: B, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> B
where A: 'a + Clone + Send + Sync, B: Send + Sync + 'a,

Folds the pair from the right in parallel (over second).

This method folds the pair by applying a function from right to left, potentially in parallel (over second).

§Type Signature

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

§Type Parameters
  • FnBrand: The brand of thread-safe function to use.
  • A: The element type (must be Send + Sync).
  • B: The accumulator type (must be Send + Sync).
§Parameters
  • func: The thread-safe function to apply to each element and the accumulator.
  • initial: The initial value.
  • fa: The pair to fold.
§Returns

The final accumulator value.

§Examples
use fp_library::classes::par_foldable::par_fold_right;
use fp_library::brands::{PairWithFirstBrand, ArcFnBrand};
use fp_library::classes::send_clonable_fn::SendClonableFn;
use fp_library::types::Pair;

let x = Pair("a".to_string(), 1);
let f = <ArcFnBrand as SendClonableFn>::new_send(|(a, b): (i32, i32)| a + b);
assert_eq!(par_fold_right::<ArcFnBrand, PairWithFirstBrand<String>, _, _>(f, 10, x), 11);
Source§

impl<First: PartialEq> PartialEq for PairWithFirstBrand<First>

Source§

fn eq(&self, other: &PairWithFirstBrand<First>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<First: PartialOrd> PartialOrd for PairWithFirstBrand<First>

Source§

fn partial_cmp(&self, other: &PairWithFirstBrand<First>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<First> Pointed for PairWithFirstBrand<First>
where First: Monoid + Clone + 'static,

Source§

fn pure<'a, A: 'a>(a: A) -> <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 a t. (Pointed (Pair t), Monoid t) => a -> Pair t a

§Type Parameters
  • 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::classes::pointed::pure;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::types::string;

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

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

Source§

fn apply<'a, FnBrand: 'a + ClonableFn, A: 'a + Clone, B: 'a>( ff: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <FnBrand as ClonableFn>::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 a b t. (Semiapplicative (Pair t), Semigroup t) => (Pair t (a -> b), Pair t a) -> Pair t b

§Type Parameters
  • FnBrand: The brand of the clonable 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::classes::semiapplicative::apply;
use fp_library::classes::clonable_fn::ClonableFn;
use fp_library::brands::PairWithFirstBrand;
use fp_library::types::Pair;
use fp_library::brands::RcFnBrand;
use fp_library::types::string;
use std::rc::Rc;

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

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

Source§

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

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 a b t. (Semimonad (Pair t), Semigroup t) => (Pair t a, a -> Pair t b) -> Pair t b

§Type Parameters
  • F: The type of the function to apply.
  • 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.
  • f: The function to apply to the second value.
§Returns

A new pair where the first values are combined.

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

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

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

Source§

fn traverse<'a, F: Applicative, Func, A: 'a + Clone, B: 'a + Clone>( func: Func, ta: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where Func: Fn(A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, <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 a b f t. (Traversable (Pair t), Applicative f) => (a -> f b, Pair t a) -> f (Pair t b)

§Type Parameters
  • F: The applicative context.
  • Func: The type of the function to apply.
  • A: The type of the elements in the traversable structure.
  • B: The type of the elements in the resulting traversable structure.
§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::classes::traversable::traverse;
use fp_library::brands::{PairWithFirstBrand, OptionBrand};
use fp_library::types::Pair;

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

fn sequence<'a, F: Applicative, A: 'a + Clone>( ta: <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 a f t. (Traversable (Pair t), Applicative f) => (Pair t (f a)) -> f (Pair t a)

§Type Parameters
  • F: The applicative context.
  • A: The type of the elements in the traversable structure.
§Parameters
  • ta: The pair containing the applicative value.
§Returns

The pair wrapped in the applicative context.

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

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

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

Source§

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

Source§

impl<First> StructuralPartialEq for PairWithFirstBrand<First>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> 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> 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<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,