Skip to content

Instantly share code, notes, and snippets.

@PlasmaPower
Created October 2, 2017 12:40
Show Gist options
  • Select an option

  • Save PlasmaPower/080b45b9b32355cd0ad1b6403a13ebc2 to your computer and use it in GitHub Desktop.

Select an option

Save PlasmaPower/080b45b9b32355cd0ad1b6403a13ebc2 to your computer and use it in GitHub Desktop.
pub struct FilterMapInput<F, M>(F, M);
impl<I, T, F: Filter<T>, M: Fn(I) -> T> Filter<I> for FilterMapInput<F, M> {
fn filter(&self, e: &I) -> bool {
self.0.filter(self.1(e))
}
}
pub struct FailableFilterMapErr<F, M>(F, M);
impl <T, EF, EO, F: FailableFilter<T, EF>, M: Fn(EF) -> EO> FailableFilter<T, EO> for FailableFilterMapErr<F, M> {
fn filter(&self, e: &T) -> Result<bool, EO> {
self.0.filter(e).map_err(self.1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment