Skip to main content

ReaderF

Struct ReaderF 

Source
pub struct ReaderF<E>(/* private fields */);
Expand description

Type constructor for the Reader functor: Of<T> = Box<dyn Fn(E) -> T>.

Isomorphic to TracedF<E> in representation, but serves a different semantic role: ReaderF<E> is the right adjoint of EnvF<E> in the product/exponential adjunction (EnvF<E> ⊣ ReaderF<E>).

ReaderF<E> cannot implement the generic Functor trait because Box<dyn Fn> requires 'static bounds that the trait signature doesn’t allow. Following the Lan pattern, inherent methods with 'static bounds on the impl block provide the same functionality.

Implementations§

Source§

impl<E> ReaderF<E>
where E: Clone + 'static,

Source

pub fn fmap<A, B>( fa: Box<dyn Fn(E) -> A>, f: impl Fn(A) -> B + 'static, ) -> Box<dyn Fn(E) -> B>
where A: 'static, B: 'static,

Functor fmap for Reader: post-compose a function.

fmap(f, reader) = |e| f(reader(e))

Source

pub fn pure<A>(a: A) -> Box<dyn Fn(E) -> A>
where A: Clone + 'static,

Applicative pure for Reader: ignore the environment, return a constant.

pure(a) = |_e| a

Source

pub fn chain<A, B>( fa: Box<dyn Fn(E) -> A>, f: impl Fn(A) -> Box<dyn Fn(E) -> B> + 'static, ) -> Box<dyn Fn(E) -> B>
where A: 'static, B: 'static,

Monadic chain (bind) for Reader: Kleisli composition.

chain(reader, f) = |e| f(reader(e))(e)

Source

pub fn ask() -> Box<dyn Fn(E) -> E>

Reader-specific: access the environment directly.

ask() = |e| e

Source

pub fn local<A>( f: impl Fn(E) -> E + 'static, reader: Box<dyn Fn(E) -> A>, ) -> Box<dyn Fn(E) -> A>
where A: 'static,

Reader-specific: modify the environment before running a reader.

local(f, reader) = |e| reader(f(e))

Trait Implementations§

Source§

impl<E> Adjunction<EnvF<E>, ReaderF<E>> for CurryAdj<E>
where E: Clone + 'static,

Available on crate features alloc or std only.
Source§

fn unit<A>(a: A) -> Box<dyn Fn(E) -> (E, A)>
where A: Clone + 'static,

unit: A -> U(F(A))
Source§

fn counit<B>(fub: (E, Box<dyn Fn(E) -> B>)) -> B
where B: 'static,

counit: F(U(B)) -> B
Source§

impl<E> HKT for ReaderF<E>
where E: 'static,

Available on crate features alloc or std only.
Source§

type Of<T> = Box<dyn Fn(E) -> T>

Auto Trait Implementations§

§

impl<E> Freeze for ReaderF<E>

§

impl<E> RefUnwindSafe for ReaderF<E>
where E: RefUnwindSafe,

§

impl<E> Send for ReaderF<E>
where E: Send,

§

impl<E> Sync for ReaderF<E>
where E: Sync,

§

impl<E> Unpin for ReaderF<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for ReaderF<E>

§

impl<E> UnwindSafe for ReaderF<E>
where E: 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.