Skip to content

Commit 4b4ca8b

Browse files
author
Fureev Eugene
committed
feat: Collection::filter
1 parent 2c19bca commit 4b4ca8b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
66

7+
## v4.17.1
8+
9+
### Changed
10+
11+
- `Collection::filter(Closure $func = null)` - The argument `$func` may be `null`
12+
713
## v4.17.0
814

915
### Added

src/Structures/Collections/ArrayCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private function getProperty(mixed $target, string|int $keyName, bool $throwOnMi
282282
* @return static
283283
* @psalm-return static<TKey,T>
284284
*/
285-
public function filter(Closure $func): static
285+
public function filter(Closure $func = null): static
286286
{
287287
return $this->createFrom(array_filter($this->elements, $func, ARRAY_FILTER_USE_BOTH));
288288
}

src/Structures/Collections/ReadableCollection.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ public function exists(Closure $func): bool;
162162
* Returns all the elements of this collection that satisfy the predicate $func.
163163
* The order of the elements is preserved.
164164
*
165-
* @param Closure $func The predicate used for filtering.
166-
* @psalm-param Closure(T, TKey):bool $func
165+
* @param null|Closure $func The predicate used for filtering.
166+
* @psalm-param null|Closure(T, TKey):bool $func
167167
*
168168
* @return ReadableCollection<mixed> A collection with the results of the filter operation.
169169
* @psalm-return ReadableCollection<TKey, T>
170170
*/
171-
public function filter(Closure $func): ReadableCollection;
171+
public function filter(Closure $func = null): ReadableCollection;
172172

173173
/**
174174
* Applies the given function to each element in the collection and returns

0 commit comments

Comments
 (0)