Skip to content

Commit

Permalink
Simplify Since and Until operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jul 18, 2020
1 parent 51c5402 commit ced44cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Operation/Compact.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ static function (iterable $collection, $values): Generator {
return yield from
(new Run(
new Filter(
/**
* @param mixed $item
*/
/**
* @param mixed $item
*/
static function ($item) use ($values): bool {
return !in_array($item, $values, true);
}
Expand Down
10 changes: 6 additions & 4 deletions src/Operation/Since.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ static function (iterable $collection, array $callbacks): Generator {
while ($iterator->valid()) {
$result = array_reduce(
$callbacks,
static function (int $carry, callable $callable) use ($iterator): int {
return $carry & $callable($iterator->current(), $iterator->key());
static function (bool $carry, callable $callable) use ($iterator): bool {
return ($callable($iterator->current(), $iterator->key())) ?
$carry :
false;
},
1
true
);

if (1 === $result) {
if (true === $result) {
break;
}

Expand Down
10 changes: 6 additions & 4 deletions src/Operation/Until.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ static function (iterable $collection, array $callbacks): Generator {

$result = array_reduce(
$callbacks,
static function (int $carry, callable $callable) use ($key, $value): int {
return $carry & $callable($value, $key);
static function (bool $carry, callable $callable) use ($key, $value): bool {
return ($callable($value, $key)) ?
$carry :
false;
},
1
true
);

if (1 === $result) {
if (true === $result) {
break;
}
}
Expand Down

0 comments on commit ced44cc

Please sign in to comment.