From 67f0052c5d6f66e3fa4111946964d4efe65c7dca Mon Sep 17 00:00:00 2001
From: Edwin Xu <edwinhuish@gmail.com>
Date: Fri, 13 Mar 2020 12:32:48 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20each=20function=20?=
 =?UTF-8?q?=E5=B9=B6=E5=92=8C=20Collection=20=E4=BF=9D=E6=8C=81=E4=B8=80?=
 =?UTF-8?q?=E8=87=B4=EF=BC=8C=E8=BF=94=E5=9B=9E=20false=20=E6=97=B6?=
 =?UTF-8?q?=E4=B8=AD=E6=96=AD=E5=BE=AA=E7=8E=AF=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/Dom/Elements.php | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/Dom/Elements.php b/src/Dom/Elements.php
index 08e7fd2..5dfa410 100644
--- a/src/Dom/Elements.php
+++ b/src/Dom/Elements.php
@@ -166,6 +166,34 @@ class Elements
         return $obj;
     }
 
+    /**
+     * Iterating elements
+     *
+     * @param  callable  $callback
+     *
+     * @return $this
+     */
+    public function each(callable $callback)
+    {
+        $break = false;
+        $this->elements->each(function ($dom) use ($callback, &$break) {
+            if ( ! $dom || $break) {
+                return;
+            }
+            $orig = $dom;
+            $dom  = new Elements(pq($dom));
+            if (false === call_user_func($callback, $dom)) {
+                $dom = $orig;
+                $break = true;
+            } else {
+                $dom = $dom->getDOMDocument();
+            }
+            unset($orig);
+        });
+
+        return $this;
+    }
+
     /**
      * Iterating elements
      *
@@ -184,7 +212,7 @@ class Elements
     /**
      * Gets the attributes of all the elements
      *
-     * @param $attr HTML attribute name
+     * @param string $attr HTML attribute name
      * @return \Illuminate\Support\Collection|\Tightenco\Collect\Support\Collection
      */
     public function attrs($attr)