Skip to content

Commit

Permalink
Fixed return type for Collection::map*. (#6798)
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed May 24, 2024
1 parent c8b9660 commit 51476aa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
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

0 comments on commit 51476aa

Please sign in to comment.