File tree Expand file tree Collapse file tree 1 file changed +17
-14
lines changed
Expand file tree Collapse file tree 1 file changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -127,13 +127,7 @@ protected function negate(callable $fn)
127127
128128 public function every (callable $ fn )
129129 {
130- foreach ($ this ->data as $ index => $ value ) {
131- if (!$ fn ($ value , $ index )) {
132- return false ;
133- }
134- }
135-
136- return true ;
130+ return $ this ->match ($ fn , true );
137131 }
138132
139133 public function all (callable $ fn )
@@ -143,20 +137,29 @@ public function all(callable $fn)
143137
144138 public function some (callable $ fn )
145139 {
146- foreach ($ this ->data as $ index => $ value ) {
147- if ($ fn ($ value , $ index )) {
148- return true ;
149- }
150- }
151-
152- return false ;
140+ return $ this ->match ($ fn , false );
153141 }
154142
155143 public function any (callable $ fn )
156144 {
157145 return $ this ->some ($ fn );
158146 }
159147
148+ protected function match (callable $ fn , $ all = true )
149+ {
150+ foreach ($ this ->data as $ index => $ value ) {
151+ if ($ all && !$ fn ($ value , $ index )) {
152+ return false ;
153+ }
154+
155+ if (!$ all && $ fn ($ value , $ index )) {
156+ return true ;
157+ }
158+ }
159+
160+ return $ all ;
161+ }
162+
160163 public function contains ($ item )
161164 {
162165 return \in_array ($ item , $ this ->data );
You can’t perform that action at this time.
0 commit comments