HashMapWitness

Struct HashMapWitness 

Source
pub struct HashMapWitness<K>(/* private fields */);
Expand description

Re-exports HashMapWitness, the HKT witness for HashMap<K, V>. HashMapWitness<K> is a zero-sized type that acts as a Higher-Kinded Type (HKT) witness for the HashMap<K, V> type constructor, where the key type K is fixed.

It allows HashMap to be used with generic functional programming traits like Functor and Foldable by fixing one of its type parameters.

Trait Implementations§

Source§

impl<K> Foldable<HashMapWitness<K>> for HashMapWitness<K>
where K: Hash + Eq + 'static,

Source§

fn fold<A, B, Func>(fa: HashMap<K, A>, init: B, f: Func) -> B
where Func: FnMut(B, A) -> B,

Folds (reduces) a HashMap into a single value.

Applies the function f cumulatively to the accumulator and each key-value pair of the hash map, starting with an initial accumulator value.

§Arguments
  • fa: The HashMap to fold.
  • init: The initial accumulator value.
  • f: The folding function, which takes the accumulator and a key-value pair.
§Returns

The final accumulated value after processing all elements.

Source§

impl<K> Functor<HashMapWitness<K>> for HashMapWitness<K>
where K: Hash + Eq + Clone + 'static,

Source§

fn fmap<A, B, Func>( m_a: <HashMapWitness<K> as HKT2<K>>::Type<A>, f: Func, ) -> <HashMapWitness<K> as HKT2<K>>::Type<B>
where Func: FnMut(A) -> B,

Implements the fmap operation for HashMap<K, V>.

Applies the function f to each value in the hash map, producing a new hash map with the same keys but transformed values.

§Arguments
  • m_a: The HashMap to map over.
  • f: The function to apply to each value.
§Returns

A new HashMap with the function applied to each of its values.

Source§

impl<K> HKT for HashMapWitness<K>

Source§

type Type<V> = HashMap<K, V>

Specifies that HashMapWitness<K> also acts as a single-parameter HKT, where the K parameter is considered part of the “witness” itself.

Source§

impl<K> HKT2<K> for HashMapWitness<K>

Source§

type Type<V> = HashMap<K, V>

Specifies that HashMapWitness<K> represents the HashMap<K, V> type constructor with a fixed key type K.

Auto Trait Implementations§

§

impl<K> Freeze for HashMapWitness<K>
where K: Freeze,

§

impl<K> RefUnwindSafe for HashMapWitness<K>
where K: RefUnwindSafe,

§

impl<K> Send for HashMapWitness<K>
where K: Send,

§

impl<K> Sync for HashMapWitness<K>
where K: Sync,

§

impl<K> Unpin for HashMapWitness<K>
where K: Unpin,

§

impl<K> UnwindSafe for HashMapWitness<K>
where K: 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> 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, 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.