File tree Expand file tree Collapse file tree 3 files changed +32
-25
lines changed Expand file tree Collapse file tree 3 files changed +32
-25
lines changed Original file line number Diff line number Diff line change @@ -736,6 +736,17 @@ public function union($items)
736736 return new static ($ this ->items + $ this ->getArrayableItems ($ items ));
737737 }
738738
739+ /**
740+ * Take items in the collection until the given condition is met.
741+ *
742+ * @param mixed $key
743+ * @return static
744+ */
745+ public function until ($ value )
746+ {
747+ return new static ($ this ->lazy ()->until ($ value )->all ());
748+ }
749+
739750 /**
740751 * Create a new collection consisting of every n-th element.
741752 *
Original file line number Diff line number Diff line change @@ -737,6 +737,27 @@ public function union($items)
737737 return $ this ->passthru ('union ' , func_get_args ());
738738 }
739739
740+ /**
741+ * Take items in the collection until the given condition is met.
742+ *
743+ * @param mixed $key
744+ * @return static
745+ */
746+ public function until ($ value )
747+ {
748+ $ callback = $ this ->useAsCallable ($ value ) ? $ value : $ this ->equality ($ value );
749+
750+ return new static (function () use ($ callback ) {
751+ foreach ($ this as $ key => $ item ) {
752+ if ($ callback ($ item , $ key )) {
753+ break ;
754+ }
755+
756+ yield $ key => $ item ;
757+ }
758+ });
759+ }
760+
740761 /**
741762 * Create a new collection consisting of every n-th element.
742763 *
Original file line number Diff line number Diff line change @@ -722,31 +722,6 @@ public function uniqueStrict($key = null)
722722 return $ this ->unique ($ key , true );
723723 }
724724
725- /**
726- * Take items in the collection until condition is met.
727- *
728- * @param mixed $key
729- * @return static
730- */
731- public function until ($ value )
732- {
733- $ passed = [];
734-
735- $ callback = $ this ->useAsCallable ($ value ) ? $ value : function ($ item ) use ($ value ) {
736- return $ item === $ value ;
737- };
738-
739- foreach ($ this as $ key => $ item ) {
740- if ($ callback ($ item , $ key )) {
741- break ;
742- }
743-
744- $ passed [$ key ] = $ item ;
745- }
746-
747- return new static ($ passed );
748- }
749-
750725 /**
751726 * Collect the values into a collection.
752727 *
You can’t perform that action at this time.
0 commit comments