Skip to main content

Bind

Trait Bind 

Source
pub trait Bind<'a, A> {
    type Target<T>;

    // Required method
    fn bind<B, F>(self, f: F) -> Self::Target<B>
       where F: Fn(A) -> Self::Target<B> + 'a;
}
Expand description

Bind lets you chain computations together.

It takes a function Fn(A) -> M<B> and applies it to the A inside M<A>. You can think of this as a callback function for when the value of A is ready to be processed, returning the next computation in the sequence.

This is the primary component of the dreaded Monad trait, but to be a Monad a type must also implement Applicative, which in turn requires implementations for Functor, Pure and Apply.

Required Associated Types§

Source

type Target<T>

Required Methods§

Source

fn bind<B, F>(self, f: F) -> Self::Target<B>
where F: Fn(A) -> Self::Target<B> + 'a,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<A> Bind<'_, A> for Option<A>

Source§

type Target<T> = Option<T>

Source§

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

Source§

impl<A> Bind<'_, A> for Vec<A>

Available on crate feature std only.
Source§

type Target<T> = Vec<T>

Source§

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

Source§

impl<A, E> Bind<'_, A> for Result<A, E>

Source§

type Target<T> = Result<T, E>

Source§

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

Implementors§

Source§

impl<'a, A> Bind<'a, A> for Effect<'a, A>
where A: 'a,

Source§

type Target<T> = Effect<'a, T>

Source§

impl<'a, A: 'a, E: 'a> Bind<'a, A> for IO<'a, A, E>

Source§

type Target<T> = IO<'a, T, E>