[][src]Trait funlib::Monad

pub trait Monad<B>: Applicative<B> {
    fn bind<F>(&self, f: F) -> Self::M
    where
        F: Fn(&Self::A) -> Self::M
; }

Monad type class

Required methods

fn bind<F>(&self, f: F) -> Self::M where
    F: Fn(&Self::A) -> Self::M

Bind works like map but it flattens nested structures

Examples

use funlib::Applicative;
use funlib::Monad;
fn over5(i: &i32) -> Option<i32> { if *i > 5 { Some(*i) } else { None }}
let a = Some(4).bind(over5);
let b = Some(6).bind(over5);
assert_eq!(None, a);
assert_eq!(Some(6), b);
Loading content...

Implementations on Foreign Types

impl<A, B> Monad<B> for Option<A>[src]

impl<A, B> Monad<B> for Box<A>[src]

impl<A, B> Monad<B> for Rc<A>[src]

impl<A, B> Monad<B> for Vec<A>[src]

Loading content...

Implementors

Loading content...