diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-09-26 18:19:55 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-09-27 21:05:11 +0200 |
commit | aae9b15675bb6ec10041ade66959f731a6ea56fe (patch) | |
tree | 9b4d4c84c457b2017411e74aa0706dc08ba49776 /src | |
parent | 211fa5a91930fcdeec11da5055e53b645139b432 (diff) |
Add WithoutFilter iterator
Diffstat (limited to 'src')
-rw-r--r-- | src/iter.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/iter.rs b/src/iter.rs index 4f178ed..0b3688f 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -127,6 +127,53 @@ impl<I, M> EveryFilter<M> for I } } +pub struct WithoutIter<I, M>(I, M) + where I: Iterator<Item = Result<TimeType>>, + M: Matcher; + +impl<I, M> WithoutIter<I, M> + where I: Iterator<Item = Result<TimeType>>, + M: Matcher +{ + fn new(i: I, m: M) -> WithoutIter<I, M> { + WithoutIter(i, m) + } +} + +impl<I, M> Iterator for WithoutIter<I, M> + where I: Iterator<Item = Result<TimeType>>, + M: Matcher +{ + type Item = Result<TimeType>; + + fn next(&mut self) -> Option<Self::Item> { + loop { + match self.0.next() { + None => return None, + Some(Err(e)) => return Some(Err(e)), + Some(Ok(tt)) => match self.1.matches(&tt) { + Ok(false) => return Some(Ok(tt)), + Ok(true) => continue, + Err(e) => return Some(Err(e)), + } + } + } + } +} + +pub trait WithoutFilter<M: Matcher> : Iterator<Item = Result<TimeType>> + Sized { + fn without(self, M) -> WithoutIter<Self, M>; +} + +impl<I, M> WithoutFilter<M> for I + where I: Iterator<Item = Result<TimeType>>, + M: Matcher +{ + fn without(self, matcher: M) -> WithoutIter<Self, M> { + WithoutIter::new(self, matcher) + } +} + pub mod extensions { use timetype::TimeType as TT; use super::Iter; @@ -394,5 +441,19 @@ mod type_tests_filter_interface { .take(12) .collect::<Vec<_>>(); } + + #[test] + fn test_compile_skip() { + // This test is solely to check whether this compiles and the API is nice + let v = TimeType::today() + .daily(1) + .unwrap() + .take(20) + .every(::indicator::Day::Monday) + .without(::indicator::Day::Monday) + .collect::<Vec<_>>(); + + assert_eq!(0, v.len()); + } } |