Skip to content

Commit 5a7a59b

Browse files
authored
clean up and improve readability of util functions (#33)
1 parent 8142b36 commit 5a7a59b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/typesense/util.clj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,32 @@
44
[clojure.walk :as walk])
55
(:import [java.net URLEncoder]))
66

7+
(defn- pair->url-parameter
8+
"Takes a pair and converts it into a url parameter."
9+
[[name value]]
10+
(str name "=" (URLEncoder/encode (str value))))
11+
712
(defn map->url-parameter-string
813
"Convert param pairs into a query string.
914
If query-params are empty returns empty string."
1015
[query-params]
1116
(if (seq query-params)
1217
(->> (walk/stringify-keys query-params)
13-
(map #(str (key %) "=" (URLEncoder/encode (str (val %)))))
14-
(str/join \&)
18+
(map pair->url-parameter)
19+
(str/join "&")
1520
(str "?"))
1621
""))
1722

23+
(defn- map->json-newline
24+
"Takes a map and return a json-newline."
25+
[m]
26+
(str (json/write-str m) "\n"))
27+
1828
(defn maps->json-lines
1929
"Take a vector of maps and returns json-line format.
2030
Returns an empty string if the vector is empty."
2131
[ms]
22-
(str/join (map #(str (json/write-str %) \newline) ms)))
32+
(str/join (map map->json-newline ms)))
2333

2434
(defn json->map
2535
"Transforms json to a map.
@@ -29,7 +39,7 @@
2939
(json/read-str json :key-fn keyword)))
3040

3141
(defn json-lines->maps
32-
"Transforms json-lines to vector of maps.
42+
"Transforms json-lines into a vector of maps.
3343
Returns empty vector if json-lines are nil or blank."
3444
[json-lines]
3545
(if (str/blank? json-lines)

0 commit comments

Comments
 (0)