Skip to content

Commit

Permalink
add skip odd even
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoikey committed Oct 2, 2024
1 parent f2d7819 commit d491d37
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/rule/collection/skip/option.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
mod no_skip;
mod skip_even_index;
mod skip_first;
mod skip_odd_index;

pub use no_skip::NoSkip;
pub use skip_even_index::SkipEvenIndex;
pub use skip_first::SkipFirst;
pub use skip_odd_index::SkipOddIndex;

pub trait SkipOption {
type Item;
Expand Down
13 changes: 13 additions & 0 deletions src/rule/collection/skip/option/skip_even_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::rule::SkipOption;

pub struct SkipEvenIndex<ITEM> {
_phantom_data: std::marker::PhantomData<ITEM>,
}

impl<ITEM> SkipOption for SkipEvenIndex<ITEM> {
type Item = ITEM;
type Accumulator = ();
fn should_skip(i: usize, _: Option<&mut Self::Accumulator>, _: &Self::Item) -> bool {
i % 2 == 0
}
}
13 changes: 13 additions & 0 deletions src/rule/collection/skip/option/skip_odd_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::rule::SkipOption;

pub struct SkipOddIndex<ITEM> {
_phantom_data: std::marker::PhantomData<ITEM>,
}

impl<ITEM> SkipOption for SkipOddIndex<ITEM> {
type Item = ITEM;
type Accumulator = ();
fn should_skip(i: usize, _: Option<&mut Self::Accumulator>, _: &Self::Item) -> bool {
i % 2 == 1
}
}

0 comments on commit d491d37

Please sign in to comment.