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)
127
127
128
128
public function every (callable $ fn )
129
129
{
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 );
137
131
}
138
132
139
133
public function all (callable $ fn )
@@ -143,20 +137,29 @@ public function all(callable $fn)
143
137
144
138
public function some (callable $ fn )
145
139
{
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 );
153
141
}
154
142
155
143
public function any (callable $ fn )
156
144
{
157
145
return $ this ->some ($ fn );
158
146
}
159
147
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
+
160
163
public function contains ($ item )
161
164
{
162
165
return \in_array ($ item , $ this ->data );
You can’t perform that action at this time.
0 commit comments