Skip to content

Commit

Permalink
concat no longer refers to itself causing infinite call loop
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed May 20, 2021
1 parent 123c0ed commit 3d6fef8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,20 @@ public static function pickRandom(array $data)
}

// A::concat([1, 2], 3, [4, 5]) -> [1, 2, 3, 4, 5]
public static function concat(...$args): array {
return self::unnest(self::map(fn($arg) => self::ensureArray($arg),$args));
public static function concat(...$args): array
{
return self::reduce(
function ($acc, $arg) {
if (self::isArray($arg) && !self::isAssoc($arg)) {
$acc = array_merge($arg, $acc);
} else {
$acc[] = $arg;
}
return $acc;
},
[],
$args
);
}

// A::zipObj(['a', 'b'], [1, 2]) -> {a:1, b:2}
Expand Down

0 comments on commit 3d6fef8

Please sign in to comment.