Skip to content

Commit

Permalink
Fixed type hinting for A::append() and A::prepend()
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed May 17, 2021
1 parent 3b9b9cb commit 5cecbe8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Plain numeric arrays are handled best via the methods in A, while associative ar

- **of** - concatenates every argument into an array as is

_See also: A::concat()_

```php
$items = A::of(1, 2, [3]); // [1, 2, [3]]
```
Expand Down Expand Up @@ -87,7 +89,17 @@ Plain numeric arrays are handled best via the methods in A, while associative ar
- **length** -
- **isEmpty** -
- **isNotEmpty** -
- **ensureArray** - wraps parameter into an array if it's anything else, than a numeric array

- **ensureArray** - wraps parameter into an array if it's not a numeric array

```php
A::ensureArray(123); // [123]
```

```php
A::ensureArray([4, 5, 6]); // [4, 5, 6]
```

- **append** -
- **prepend** -
- **pluck** -
Expand Down Expand Up @@ -272,11 +284,14 @@ Plain numeric arrays are handled best via the methods in A, while associative ar

- **includes** -
- **contains** -

- **slice** -
- **join** -

- **pickRandom** - selects a random item from the given array
- **concat** - concatenates every argument into an array. if any of the arguments are arrays, then those will get unnested

- **concat** - concatenates every argument into an array. if any of the arguments are numeric arrays, then those will get unnested

_See also: A::of()_

```php
A::concat([1, 2], 3, [4, 5]); // [1, 2, 3, 4, 5]
Expand Down
8 changes: 4 additions & 4 deletions src/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public static function ensureArray($data): array
}

// A::append([4, 5, 6], [1, 2]) -> [1, 2, 4, 5, 6]
public static function append(array $arr, array $data): array
public static function append($value, array $data): array
{
return array_merge($data, self::ensureArray($arr));
return self::concat($data, $value);
}

// A::prepend([4, 5, 6], [1, 2]) -> [4, 5, 6, 1, 2]
public static function prepend(array $arr, array $data): array
public static function prepend($value, array $data): array
{
return array_merge(self::ensureArray($arr), $data);
return self::concat($value, $data);
}

// A::pluck('color', [['color' => 'red', ...], ['color' => 'green', ...]]) -> ['red', 'green']
Expand Down

0 comments on commit 5cecbe8

Please sign in to comment.