Skip to content

Commit

Permalink
fix: use reduce instead of loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
smeghead committed Aug 25, 2024
1 parent 7349799 commit 5780e32
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/statement.phel
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

(defn- map-key-to-keyowrd [row]
(let [row (php-array-to-map row)]
(loop [ps (keys row)
acc {}]
(if (empty? ps)
acc
(recur
(rest ps)
(put acc (keyword (first ps)) (row (first ps))))))))
(reduce (fn [acc key]
(put acc (keyword key) (row key)))
{} (keys row))))

(defn fetch
"Fetches the next row from a result set"
Expand All @@ -36,13 +32,9 @@
(fetchAll (php/:: \PDO FETCH_ASSOC)))))

(defn- map-key-to-string [params]
(loop [ps (keys params)
acc {}]
(if (empty? ps)
(to-php-array acc)
(recur
(rest ps)
(put acc (format "%s" (first ps)) (params (first ps)))))))
(to-php-array (reduce (fn [acc key]
(put acc (format "%s" key) (params key)))
{} (keys params))))

(defn execute
"Executes a prepared statement"
Expand Down

0 comments on commit 5780e32

Please sign in to comment.