Skip to content

Conversation

lmottasin
Copy link
Contributor

Description

This pull request updates the PHPDoc block for the mapSpread method in the Arr class to improve accuracy and clarity. The updated doc block provides more specific type hints for the parameters and return type.

Changes

  • Added @template TKey to indicate the keys are preserved.
  • Updated the @param type for $array to array<TKey, array> to specify the structure of the input array.

Before

/**
 * Run a map over each nested chunk of items.
 *
 * @template TMapSpreadValue
 *
 * @param  array  $array
 * @param  callable(mixed...): TMapSpreadValue  $callback
 * @return array<TKey, TMapSpreadValue>
 */
public static function mapSpread(array $array, callable $callback)
{
    return static::map($array, function ($chunk, $key) use ($callback) {
        $chunk[] = $key;

        return $callback(...$chunk);
    });
}

After

/**
 * Run a map over each nested chunk of items.
 *
 * @template TKey
 * @template TMapSpreadValue
 *
 * @param  array<TKey, array>  $array
 * @param  callable(mixed...): TMapSpreadValue  $callback
 * @return array<TKey, TMapSpreadValue>
 */
public static function mapSpread(array $array, callable $callback)
{
    return static::map($array, function ($chunk, $key) use ($callback) {
        $chunk[] = $key;

        return $callback(...$chunk);
    });
}

taylorotwell and others added 2 commits June 28, 2024 22:06
Co-authored-by: Caleb White <cdwhite3@pm.me>
@taylorotwell taylorotwell merged commit bbb4678 into laravel:11.x Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants