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,
impl<E> ReaderF<E>where
E: Clone + 'static,
Sourcepub 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,
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))
Sourcepub fn pure<A>(a: A) -> Box<dyn Fn(E) -> A>where
A: Clone + 'static,
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
Sourcepub 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,
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)