Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed return type for Collection::map*. #6798

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG-3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Fixed

- [#6796](https://github.com/hyperf/hyperf/pull/6796) Fixed bug that the return type of `Collection::mapInto()` is invalid sometimes.
- [#6796](https://github.com/hyperf/hyperf/pull/6796) [#6798](https://github.com/hyperf/hyperf/pull/6798) Fixed bug that the return type of `Collection::mapInto()` is invalid sometimes.

## Added

Expand Down
4 changes: 2 additions & 2 deletions src/collection/src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ public function map(callable $callback): self|static
* @param callable(TValue, TKey): array<TMapToDictionaryKey, TMapToDictionaryValue> $callback
* @return static<TMapToDictionaryKey, array<int, TMapToDictionaryValue>>
*/
public function mapToDictionary(callable $callback): static
public function mapToDictionary(callable $callback): self|static
{
$dictionary = [];
foreach ($this->items as $key => $item) {
Expand All @@ -689,7 +689,7 @@ public function mapToDictionary(callable $callback): static
* @param callable(TValue, TKey): array<TMapWithKeysKey, TMapWithKeysValue> $callback
* @return static<TMapWithKeysKey, TMapWithKeysValue>
*/
public function mapWithKeys(callable $callback): static
public function mapWithKeys(callable $callback): self|static
{
return new static(Arr::mapWithKeys($this->items, $callback));
}
Expand Down
10 changes: 5 additions & 5 deletions src/collection/src/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ public function map(callable $callback): self|static;
/**
* Run a map over each nested chunk of items.
*/
public function mapSpread(callable $callback): static;
public function mapSpread(callable $callback): self|static;

/**
* Run a dictionary map over the items.
Expand All @@ -648,7 +648,7 @@ public function mapSpread(callable $callback): static;
* @param callable(TValue, TKey): array<TMapToDictionaryKey, TMapToDictionaryValue> $callback
* @return static<TMapToDictionaryKey, array<int, TMapToDictionaryValue>>
*/
public function mapToDictionary(callable $callback): static;
public function mapToDictionary(callable $callback): self|static;

/**
* Run a grouping map over the items.
Expand All @@ -661,7 +661,7 @@ public function mapToDictionary(callable $callback): static;
* @param callable(TValue, TKey): array<TMapToGroupsKey, TMapToGroupsValue> $callback
* @return static<TMapToGroupsKey, static<int, TMapToGroupsValue>>
*/
public function mapToGroups(callable $callback): static;
public function mapToGroups(callable $callback): self|static;

/**
* Run an associative map over each of the items.
Expand All @@ -674,7 +674,7 @@ public function mapToGroups(callable $callback): static;
* @param callable(TValue, TKey): array<TMapWithKeysKey, TMapWithKeysValue> $callback
* @return static<TMapWithKeysKey, TMapWithKeysValue>
*/
public function mapWithKeys(callable $callback);
public function mapWithKeys(callable $callback): self|static;

/**
* Map a collection and flatten the result by a single level.
Expand All @@ -685,7 +685,7 @@ public function mapWithKeys(callable $callback);
* @param callable(TValue, TKey): (array<TFlatMapKey, TFlatMapValue>|Collection<TFlatMapKey, TFlatMapValue>) $callback
* @return static<TFlatMapKey, TFlatMapValue>
*/
public function flatMap(callable $callback): static;
public function flatMap(callable $callback): self|static;

/**
* Map the values into a new class.
Expand Down
4 changes: 2 additions & 2 deletions src/collection/src/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public function map(callable $callback): self|static
* @param callable(TValue, TKey): array<TMapToDictionaryKey, TMapToDictionaryValue> $callback
* @return static<TMapToDictionaryKey, array<int, TMapToDictionaryValue>>
*/
public function mapToDictionary(callable $callback): static
public function mapToDictionary(callable $callback): self|static
{
return $this->passthru('mapToDictionary', func_get_args());
}
Expand All @@ -804,7 +804,7 @@ public function mapToDictionary(callable $callback): static
* @param callable(TValue, TKey): array<TMapWithKeysKey, TMapWithKeysValue> $callback
* @return static<TMapWithKeysKey, TMapWithKeysValue>
*/
public function mapWithKeys(callable $callback)
public function mapWithKeys(callable $callback): self|static
{
return new static(function () use ($callback) {
foreach ($this as $key => $value) {
Expand Down
6 changes: 3 additions & 3 deletions src/collection/src/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public function isNotEmpty(): bool
* @param callable(mixed...): TMapSpreadValue $callback
* @return static<TKey, TMapSpreadValue>
*/
public function mapSpread(callable $callback): static
public function mapSpread(callable $callback): self|static
{
return $this->map(function ($chunk, $key) use ($callback) {
$chunk[] = $key;
Expand All @@ -428,7 +428,7 @@ public function mapSpread(callable $callback): static
* @param callable(TValue, TKey): array<TMapToGroupsKey, TMapToGroupsValue> $callback
* @return static<TMapToGroupsKey, static<int, TMapToGroupsValue>>
*/
public function mapToGroups(callable $callback): static
public function mapToGroups(callable $callback): self|static
{
$groups = $this->mapToDictionary($callback);

Expand All @@ -444,7 +444,7 @@ public function mapToGroups(callable $callback): static
* @param callable(TValue, TKey): (array<TFlatMapKey, TFlatMapValue>|Collection<TFlatMapKey, TFlatMapValue>) $callback
* @return static<TFlatMapKey, TFlatMapValue>
*/
public function flatMap(callable $callback): static
public function flatMap(callable $callback): self|static
{
return $this->map($callback)->collapse();
}
Expand Down
Loading