Skip to content

Commit

Permalink
add accumulator
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoikey committed Oct 2, 2024
1 parent 956dbd1 commit 6bfee00
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/rule/collection/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ where
let mut remains = target.into_iterator();
let mut result = VecDeque::new();
let (mut is_valid, mut message) = (true, String::new());
let mut accumlator = None;
for (i, item) in remains.by_ref().enumerate() {
if OPTION::should_skip(i, &item) {
if OPTION::should_skip(i, &item, accumlator.as_mut()) {
result.push_back(item);
continue;
}
Expand Down
7 changes: 6 additions & 1 deletion src/rule/collection/skip/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ pub use skip_first::SkipFirst;

pub trait SkipOption {
type Item;
fn should_skip(i: usize, item: &Self::Item) -> bool;
type Accumulator;
fn should_skip(
i: usize,
item: &Self::Item,
accumulator: Option<&mut Self::Accumulator>,
) -> bool;
}
3 changes: 2 additions & 1 deletion src/rule/collection/skip/option/no_skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub struct NoSkip<T> {

impl<ITEM> SkipOption for NoSkip<ITEM> {
type Item = ITEM;
fn should_skip(_: usize, _: &Self::Item) -> bool {
type Accumulator = ();
fn should_skip(_: usize, _: &Self::Item, _: Option<&mut Self::Accumulator>) -> bool {
false
}
}
3 changes: 2 additions & 1 deletion src/rule/collection/skip/option/skip_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub struct SkipFirst<ITEM> {

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

0 comments on commit 6bfee00

Please sign in to comment.