Last active
April 21, 2016 06:25
-
-
Save charlesetc/683c036e550ea833a70be83dda5ff4e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl<T> Monad<T, Vec<T>> for Vec<T> { | |
fn returns(inside: T) -> Self { | |
vec!(inside) | |
} | |
fn bind<'a>(outside: Self, op: Box<Fn(T) -> Self + 'a>) -> Self | |
{ | |
outside | |
.into_iter() | |
.fold(vec![], |mut agg, x| { | |
let mut c = &mut op(x); | |
agg.append(c); | |
agg | |
}) | |
} | |
} | |
impl<T> Monad<T, Vec<Vec<T>>> for Vec<T> { | |
fn returns(inside: T) -> Self { | |
vec!(inside) | |
} | |
fn bind<'a>(outside: Self, op: Box<Fn(T) -> Vec<Vec<T>> + 'a>) -> Vec<Vec<T>> | |
{ | |
outside | |
.into_iter() | |
.fold(vec![], |mut agg, x| { | |
let mut c = &mut op(x); | |
agg.append(c); | |
agg | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment