From 5c7187da5eb2e87ab0f6d305e1915e5100eeb62b Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Mon, 9 Jan 2023 12:29:16 +0100 Subject: [PATCH] Exit early in `TrinaryLogic::lazyAnd()` and `lazyOr()` if current instance allows it --- src/TrinaryLogic.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/TrinaryLogic.php b/src/TrinaryLogic.php index 259ac81fa5..5c4c3782fa 100644 --- a/src/TrinaryLogic.php +++ b/src/TrinaryLogic.php @@ -94,6 +94,10 @@ public function lazyAnd( callable $callback, ): self { + if ($this->no()) { + return $this; + } + $results = []; foreach ($objects as $object) { $result = $callback($object); @@ -124,6 +128,10 @@ public function lazyOr( callable $callback, ): self { + if ($this->yes()) { + return $this; + } + $results = []; foreach ($objects as $object) { $result = $callback($object);