File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed
Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ public function findAny()
6363 return $ this ->decoratedStream ->findAny ();
6464 }
6565
66- public function findFirst ()
66+ public function findFirst (callable $ filter = null )
6767 {
6868 return $ this ->decoratedStream ->findFirst ();
6969 }
Original file line number Diff line number Diff line change @@ -205,11 +205,20 @@ public function findAny()
205205 /**
206206 * @inheritDoc
207207 */
208- public function findFirst ()
208+ public function findFirst (callable $ filter = null )
209209 {
210+ if (!$ filter ) {
211+ /** @noinspection LoopWhichDoesNotLoopInspection */
212+ foreach ($ this ->list as $ item ) {
213+ return $ item ;
214+ }
215+ return null ;
216+ }
210217 /** @noinspection LoopWhichDoesNotLoopInspection */
211218 foreach ($ this ->list as $ item ) {
212- return $ item ;
219+ if ($ filter ($ item )) {
220+ return $ item ;
221+ }
213222 }
214223 return null ;
215224 }
Original file line number Diff line number Diff line change @@ -71,9 +71,10 @@ public function findAny();
7171
7272 /**
7373 * Returns first collection element or null if absent
74+ * @param callable|null $filter
7475 * @return mixed
7576 */
76- public function findFirst ();
77+ public function findFirst (callable $ filter = null );
7778
7879 /**
7980 * Returns last collection element or null if absent
You can’t perform that action at this time.
0 commit comments