diff --git a/src/Operation/DropWhile.php b/src/Operation/DropWhile.php index 222c27ac4..1e15fad84 100644 --- a/src/Operation/DropWhile.php +++ b/src/Operation/DropWhile.php @@ -44,16 +44,20 @@ public function __invoke(): Closure * @return Generator */ 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; } }; } diff --git a/src/Operation/Since.php b/src/Operation/Since.php index 3a18f24b0..1e7cb21a5 100644 --- a/src/Operation/Since.php +++ b/src/Operation/Since.php @@ -44,16 +44,20 @@ public function __invoke(): Closure * @return Generator */ 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; } }; }