Skip to content

Commit 9d212bc

Browse files
author
Fureev Eugene
committed
feat: add Collection::reject
1 parent 4b4ca8b commit 9d212bc

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
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.18.0
8+
9+
### Added
10+
11+
- Add function `Collection::reject`
12+
713
## v4.17.1
814

915
### Changed

src/Structures/Collections/ArrayCollection.php

+11
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ public function filter(Closure $func = null): static
287287
return $this->createFrom(array_filter($this->elements, $func, ARRAY_FILTER_USE_BOTH));
288288
}
289289

290+
/**
291+
* {@inheritDoc}
292+
*
293+
* @return static
294+
* @psalm-return static<TKey,T>
295+
*/
296+
public function reject(Closure $callback): static
297+
{
298+
return $this->filter(static fn($value, $key) => !$callback($value, $key));
299+
}
300+
290301
/**
291302
* {@inheritDoc}
292303
*/

src/Structures/Collections/ReadableCollection.php

+11
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ public function exists(Closure $func): bool;
170170
*/
171171
public function filter(Closure $func = null): ReadableCollection;
172172

173+
/**
174+
* Create a collection of all elements that do not pass a given truth test.
175+
*
176+
* @param Closure $func The predicate used for filtering.
177+
* @psalm-param Closure(T, TKey):bool $func
178+
*
179+
* @return ReadableCollection<mixed> A collection with the results of the filter operation.
180+
* @psalm-return ReadableCollection<TKey, T>
181+
*/
182+
public function reject(Closure $callback): ReadableCollection;
183+
173184
/**
174185
* Applies the given function to each element in the collection and returns
175186
* a new collection with the elements returned by the function.

0 commit comments

Comments
 (0)