diff --git a/src/Lib/Collections.php b/src/Lib/Collections.php index d9bf3a7..9561665 100644 --- a/src/Lib/Collections.php +++ b/src/Lib/Collections.php @@ -150,7 +150,11 @@ class Collections implements ILib $env->set('chunk', new CoreFunc('chunk', 'Divide first argument (sequence) into new sequences with length of second argument (int).', 2, 2, function (Seq $a, int $len) { $chunks = array_chunk($a->getData(), $len); - return $a::new(array_map(fn ($b) => $a::new($b), $chunks)); + $data = []; + foreach ($chunks as $c) { + $data[] = $a::new($c); + } + return $a::new($data); } )); @@ -159,7 +163,11 @@ class Collections implements ILib // This is used by quasiquote, so we need to always return // a list for it to work properly. - $data = array_map(fn ($a) => $a->getData(), $args); + $data = []; + foreach ($args as $a) { + $data[] = $a->getData(); + } + return new MList(array_merge(...$data)); } )); diff --git a/src/Lib/Database.php b/src/Lib/Database.php index c0b9da0..a889832 100644 --- a/src/Lib/Database.php +++ b/src/Lib/Database.php @@ -29,13 +29,15 @@ class Database implements ILib )); $env->set('db-query', new CoreFunc('db-query', 'Execute a database query.', 2, 4, - function (PDO $pdo, string $sql, ?Collection $args, bool $rowVectors = false) { + function (PDO $pdo, string $sql, ?Collection $args = null, bool $rowVectors = false) { $stmt = $pdo->prepare($sql); $stmt->execute($args ? $args->getData() : []); $rows = $stmt->fetchAll($rowVectors ? PDO::FETCH_NUM : PDO::FETCH_ASSOC); - return new Vector( - array_map(fn ($row) => $rowVectors ? new Vector($row) : new Hash($row), $rows) - ); + $data = []; + foreach ($rows as $row) { + $data[] = $rowVectors ? new Vector($row) : new Hash($row); + } + return new Vector($data); } )); diff --git a/src/Lib/Types.php b/src/Lib/Types.php index 5e92aab..1c5a565 100644 --- a/src/Lib/Types.php +++ b/src/Lib/Types.php @@ -30,7 +30,17 @@ class Types implements ILib )); $env->set('str', new CoreFunc('str', 'Convert arguments to string and concatenate them together.', 0, -1, - fn (...$args) => implode('', array_map([$this, 'getStrValue'], $args)) + function (...$args) { + $data = []; + foreach ($args as $a) { + if ($a instanceof Symbol) { + $data[] = $a->getName(); + } else { + $data[] = strval($a); + } + } + return implode('', $data); + } )); $env->set('symbol', new CoreFunc('symbol', 'Convert argument to symbol.', 1, 1, @@ -167,13 +177,4 @@ class Types implements ILib fn ($a) => $a % 2 !== 0 )); } - - private function getStrValue($a) - { - if ($a instanceof Symbol) { - return $a->getName(); - } - - return strval($a); - } }