diff --git a/src/Collection.php b/src/Collection.php index 5344393be..bb691dc94 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -527,9 +527,9 @@ public static function times($number = INF, ?callable $callback = null): Collect * * @return \loophp\collection\Contract\Collection */ - public function until(callable $callback): BaseInterface + public function until(callable ...$callbacks): BaseInterface { - return $this->run(new Until($callback)); + return $this->run(new Until(...$callbacks)); } /** diff --git a/src/Contract/Untilable.php b/src/Contract/Untilable.php index 5a3f06bd8..dbdf271e7 100644 --- a/src/Contract/Untilable.php +++ b/src/Contract/Untilable.php @@ -10,9 +10,9 @@ interface Untilable { /** - * @param callable $callable + * @param callable ...$callbacks * * @return \loophp\collection\Contract\Collection */ - public function until(callable $callable): Base; + public function until(callable ...$callbacks): Base; } diff --git a/src/Operation/Until.php b/src/Operation/Until.php index 8b2c9a82e..883a443ec 100644 --- a/src/Operation/Until.php +++ b/src/Operation/Until.php @@ -14,18 +14,18 @@ final class Until implements Operation { /** - * @var callable + * @var array */ - private $callable; + private $callbacks; /** * Until constructor. * - * @param callable $callable + * @param callable ...$callbacks */ - public function __construct(callable $callable) + public function __construct(callable ...$callbacks) { - $this->callable = $callable; + $this->callbacks = $callbacks; } /** @@ -33,13 +33,19 @@ public function __construct(callable $callable) */ public function on(iterable $collection): Closure { - $callable = $this->callable; + $callbacks = $this->callbacks; - return static function () use ($callable, $collection): Generator { + return static function () use ($callbacks, $collection): Generator { foreach ($collection as $key => $value) { yield $key => $value; - if (true === $callable($value, $key)) { + $result = true; + + foreach ($callbacks as $callback) { + $result &= $callback($value, $key); + } + + if (1 === $result) { break; } }