BTreeMapWitness

Struct BTreeMapWitness 

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

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

It allows BTreeMap 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<BTreeMapWitness<K>> for BTreeMapWitness<K>
where K: Ord + 'static,

Source§

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

Folds (reduces) a BTreeMap into a single value.

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

§Arguments
  • fa: The BTreeMap 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<BTreeMapWitness<K>> for BTreeMapWitness<K>
where K: Ord + Clone + 'static,

Source§

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

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

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

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

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

Source§

impl<K> HKT for BTreeMapWitness<K>

Source§

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

Specifies that BTreeMapWitness<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 BTreeMapWitness<K>

Source§

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

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K> UnwindSafe for BTreeMapWitness<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.