Skip to content

Commit 9cd7fb4

Browse files
author
Fureev Eugene
committed
feat: add whereInstanceOf
1 parent e7fb26a commit 9cd7fb4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ 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.21.0
8+
9+
### Added
10+
11+
- Add method `whereInstanceOf` into `ArrayCollection`
12+
713
## v4.20.0
814

915
### Added
1016

11-
- Add method `slugifyWithFormat` into Str
17+
- Add method `slugifyWithFormat` into `Str`
1218

1319
## v4.19.0
1420

src/Structures/Collections/ArrayCollection.php

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

290+
public function whereInstanceOf(string|array $type): static
291+
{
292+
return $this->filter(
293+
static function ($value) use ($type) {
294+
foreach ((array)$type as $classType) {
295+
if ($value instanceof $classType) {
296+
return true;
297+
}
298+
}
299+
300+
return false;
301+
}
302+
);
303+
}
304+
290305
/**
291306
* {@inheritDoc}
292307
*

0 commit comments

Comments
 (0)