Skip to content

Commit

Permalink
Fix the behavior of the ::apply() operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 8, 2020
1 parent 486b835 commit 719eea8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ static function ($item) {
->apply($callback)
->shouldThrow(Exception::class)
->during('all');

$apply1 = static function ($value) {
return $value % 2 === true;
};

$apply2 = static function ($value) {
return $value % 3 === true;
};

$this::with([1, 2, 3, 4, 5, 6])
->apply($apply1)
->apply($apply2)
->shouldIterateAs([1, 2, 3, 4 ,5 ,6]);
}

public function it_can_be_constructed_from_array(): void
Expand Down
5 changes: 4 additions & 1 deletion src/Operation/Apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public function on(iterable $collection): Closure
return static function () use ($callbacks, $collection): Generator {
foreach ($collection as $key => $value) {
foreach ($callbacks as $callback) {
$callback($value, $key);
if (true === $callback($value, $key)) {
continue;
}
break;
}

yield $key => $value;
Expand Down

0 comments on commit 719eea8

Please sign in to comment.