Skip to content

Commit

Permalink
Update Split operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 20, 2020
1 parent d1be59e commit 84e6381
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Operation/Split.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@ static function (Iterator $iterator, array $callbacks): Generator {
$carry = [];

foreach ($iterator as $key => $value) {
$callbackReturn = array_reduce(
$callbacks,
static function ($carry, callable $callback) use ($key, $value): bool {
// @todo : Do this everywhere.
return $callback($value, $key) !== $carry;
},
true
);

$carry[] = $value;

foreach ($callbacks as $callback) {
if (true !== $callback($value, $key)) {
continue;
}
if (true === $callbackReturn) {
continue;
}

yield $carry;
yield $carry;

$carry = [];
}
$carry = [];
}

if ([] !== $carry) {
Expand Down

0 comments on commit 84e6381

Please sign in to comment.