Skip to content

Instantly share code, notes, and snippets.

@jimmycuadra
Created July 11, 2017 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmycuadra/4c1599e9b1b75460b95963e908c7447d to your computer and use it in GitHub Desktop.
Save jimmycuadra/4c1599e9b1b75460b95963e908c7447d to your computer and use it in GitHub Desktop.
struct Client {
members: Vec<Member>,
}
impl Client {
fn first_ok<F>(&self, callback: F) -> Result<GoodThing, Vec<BadThing>>
where
F: Fn(&Member) -> Result<GoodThing, BadThing>
{
let mut errors = Vec::with_capacity(self.members.len());
for member in self.members.iter() {
let result = callback(member);
match result {
Ok(node) => return Ok(node),
Err(error) => errors.push(error),
}
}
Err(errors)
}
}
@jimmycuadra
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment