Skip to content

Commit

Permalink
refactor: Minor optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 30, 2022
1 parent 11bee15 commit 9ac298a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 10 additions & 6 deletions src/Operation/DropWhile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ public function __invoke(): Closure
* @return Generator<TKey, T>
*/
static function (Iterator $iterator) use ($callbacks): Generator {
$skip = false;

foreach ($iterator as $key => $current) {
if (CallbacksArrayReducer::or()($callbacks, $current, $key, $iterator)) {
if (false === $skip) {
if (false === CallbacksArrayReducer::or()($callbacks, $current, $key, $iterator)) {
$skip = true;

yield $key => $current;
}

continue;
}

break;
}

for (; $iterator->valid(); $iterator->next()) {
yield $iterator->key() => $iterator->current();
yield $key => $current;
}
};
}
Expand Down
16 changes: 10 additions & 6 deletions src/Operation/Since.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ public function __invoke(): Closure
* @return Generator<TKey, T>
*/
static function (Iterator $iterator) use ($callbacks): Generator {
$skip = false;

foreach ($iterator as $key => $current) {
if (!CallbacksArrayReducer::or()($callbacks, $current, $key, $iterator)) {
if (false === $skip) {
if (true === CallbacksArrayReducer::or()($callbacks, $current, $key, $iterator)) {
$skip = true;

yield $key => $current;
}

continue;
}

break;
}

for (; $iterator->valid(); $iterator->next()) {
yield $iterator->key() => $iterator->current();
yield $key => $current;
}
};
}
Expand Down

0 comments on commit 9ac298a

Please sign in to comment.