Skip to main content

Density

Struct Density 

Source
pub struct Density<W, A>
where W: HKT + 'static, A: 'static,
{ /* private fields */ }
Expand description

Density Comonad — the CPS dual of Codensity.

Density<W, A> ≅ ∃S. (W S → A, W S)

This is the left Kan extension of W along itself (Lan W W A), specialised into a concrete type with existential state.

§Key properties

  • extract: Requires no bounds on W — just applies the stored function.
  • fmap: Composes onto the extract function, no bounds on W.

Note: Due to Rust’s GAT limitations, DensityF does not implement HKT or Comonad. Use inherent methods instead.

Implementations§

Source§

impl<W, A> Density<W, A>
where W: HKT + 'static, A: 'static,

Source

pub fn lift<S>( source: <W as HKT>::Of<S>, f: impl Fn(&<W as HKT>::Of<S>) -> A + 'static, ) -> Density<W, A>
where S: 'static, <W as HKT>::Of<S>: 'static,

Construct a Density from a source value and an extract function.

Source

pub fn extract(&self) -> A

Extract the value. No bounds on W required.

Source

pub fn fmap<B>(self, f: impl Fn(A) -> B + 'static) -> Density<W, B>
where B: 'static,

Map a function over the result. No bounds on W required.

Auto Trait Implementations§

§

impl<W, A> Freeze for Density<W, A>

§

impl<W, A> !RefUnwindSafe for Density<W, A>

§

impl<W, A> !Send for Density<W, A>

§

impl<W, A> !Sync for Density<W, A>

§

impl<W, A> Unpin for Density<W, A>

§

impl<W, A> UnsafeUnpin for Density<W, A>

§

impl<W, A> !UnwindSafe for Density<W, A>

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.