From 3d6fef810ed5f23c5ab98bd6963e10f98e176065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lajos=20M=C3=A9sz=C3=A1ros?= Date: Thu, 20 May 2021 15:02:32 +0200 Subject: [PATCH] concat no longer refers to itself causing infinite call loop --- src/A.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/A.php b/src/A.php index 0495ce1..25c6237 100644 --- a/src/A.php +++ b/src/A.php @@ -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}