2018-12-17 04:21:47 +01:00
|
|
|
trait VecMonad<A> {
|
2015-01-03 16:45:00 +01:00
|
|
|
fn bind<B, F>(&self, f: F) where F: FnMut(A) -> Vec<B>;
|
2012-07-12 00:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-12-17 04:21:47 +01:00
|
|
|
impl<A> VecMonad<A> for Vec<A> {
|
2015-01-03 16:45:00 +01:00
|
|
|
fn bind<B, F>(&self, mut f: F) where F: FnMut(A) -> Vec<B> {
|
2014-10-09 21:17:22 +02:00
|
|
|
let mut r = panic!();
|
2015-01-31 18:20:46 +01:00
|
|
|
for elt in self { r = r + f(*elt); }
|
2015-03-30 10:56:24 +02:00
|
|
|
//~^ ERROR E0277
|
2012-04-08 02:11:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn main() {
|
2015-02-01 18:44:15 +01:00
|
|
|
["hi"].bind(|x| [x] );
|
2017-03-23 02:07:02 +01:00
|
|
|
//~^ ERROR no method named `bind` found for type `[&str; 1]` in the current scope
|
2012-07-12 00:00:40 +02:00
|
|
|
}
|