Trait fmap::Applicative

source ·
pub trait Applicative<'a, B>where
    Self: Pure<'a, B> + Pure<'a, BoxMapper<'a, Self, B>>,
    B: 'a,{
    // Required method
    fn apply(
        self,
        f: <Self as Functor<'a, BoxMapper<'a, Self, B>>>::Mapped
    ) -> <Self as Functor<'a, B>>::Mapped;
}
Expand description

An applicative Functor

Note: In functional programming, every monad is also an applicative functor. The Monad trait, however, does not have Applicative as superclass, because it is not possible to provide a corresponding Applicative implementation for every monad. The reason is that (unlike in functional programming) values in Rust may be moved and only used once. The Applicative implementation for Vec<A> demands A: Clone, for example, while the Monad implementation for Vec<A> does not put any bounds on A. The requirements for a monad to be able to implement Applicative::apply through monad_apply are:

Examples

use fmap::Applicative;

let f: Vec<Box<dyn Send + FnMut(i32) -> i32>> =
    vec![Box::new(|x| x), Box::new(|x| x * 100)];
let a = vec![4, 7, 9];
let b = a.apply(f);
assert_eq!(b, vec![4, 7, 9, 400, 700, 900]);

Required Methods§

source

fn apply( self, f: <Self as Functor<'a, BoxMapper<'a, Self, B>>>::Mapped ) -> <Self as Functor<'a, B>>::Mapped

Like Functor::fmap, but takes a wrapped (and boxed) mapping function

Implementations on Foreign Types§

source§

impl<'a, A, B, E> Applicative<'a, B> for Result<A, E>where A: 'a, B: 'a,

source§

fn apply(self, f: Result<BoxMapper<'a, Self, B>, E>) -> Result<B, E>

source§

impl<'a, A, B> Applicative<'a, B> for Pin<Box<dyn Future<Output = A> + Send + 'a>>where A: 'a, B: 'a + Send,

source§

fn apply( self, f: Pin<Box<dyn Future<Output = BoxMapper<'a, Self, B>> + Send + 'a>> ) -> Pin<Box<dyn Future<Output = B> + Send + 'a>>

source§

impl<'a, A, B> Applicative<'a, B> for Box<dyn Send + FnOnce() -> A + 'a>where A: 'a, B: 'a + Send,

source§

fn apply( self, f: Box<dyn Send + FnOnce() -> BoxMapper<'a, Self, B> + 'a> ) -> Box<dyn Send + FnOnce() -> B + 'a>

source§

impl<'a, A, B, X> Applicative<'a, B> for Box<dyn Send + FnOnce(X) -> A + 'a>where A: 'a, B: 'a + Send, X: 'a + Clone,

source§

fn apply( self, f: Box<dyn Send + FnOnce(X) -> BoxMapper<'a, Self, B> + 'a> ) -> Box<dyn Send + FnOnce(X) -> B + 'a>

source§

impl<'a, A, B> Applicative<'a, B> for Pin<Box<dyn Future<Output = A> + 'a>>where A: 'a, B: 'a,

source§

fn apply( self, f: Pin<Box<dyn Future<Output = BoxMapper<'a, Self, B>> + 'a>> ) -> Pin<Box<dyn Future<Output = B> + 'a>>

source§

impl<'a, A, B, X> Applicative<'a, B> for Box<dyn FnOnce(X) -> A + 'a>where A: 'a, B: 'a, X: 'a + Clone,

source§

fn apply( self, f: Box<dyn FnOnce(X) -> BoxMapper<'a, Self, B> + 'a> ) -> Box<dyn FnOnce(X) -> B + 'a>

source§

impl<'a, A, B> Applicative<'a, B> for Vec<A>where A: 'a + Clone, B: 'a,

source§

fn apply(self, f: Vec<BoxMapper<'a, Self, B>>) -> Vec<B>

source§

impl<'a, A, B> Applicative<'a, B> for Box<dyn FnOnce() -> A + 'a>where A: 'a, B: 'a,

source§

fn apply( self, f: Box<dyn FnOnce() -> BoxMapper<'a, Self, B> + 'a> ) -> Box<dyn FnOnce() -> B + 'a>

source§

impl<'a, A, B> Applicative<'a, B> for VecDeque<A>where A: 'a + Clone, B: 'a,

source§

fn apply(self, f: VecDeque<BoxMapper<'a, Self, B>>) -> VecDeque<B>

source§

impl<'a, A, B> Applicative<'a, B> for LinkedList<A>where A: 'a + Clone, B: 'a,

source§

fn apply(self, f: LinkedList<BoxMapper<'a, Self, B>>) -> LinkedList<B>

source§

impl<'a, A, B> Applicative<'a, B> for Option<A>where A: 'a, B: 'a,

source§

fn apply(self, f: Option<BoxMapper<'a, Self, B>>) -> Option<B>

Implementors§