【发布时间】:2020-11-05 00:27:46
【问题描述】:
我希望函数 (string-place-typeII) 从 (calculate-distance-matrix) 返回值,如下所示:{:distance "5 km" :duration "2 mins"} 在每个循环中或 更好 将其传递给包含在 {} 中的某个变量,所以我可以在循环结束时返回所有这些。
功能列表:
(defn get-placetypes
""
[] (into-array (PlaceType/values )) )
(defn get-all-placetypes
""
[x]
(def my-vector (get-placetypes))
(let [[& the-rest] my-vector]
(nth the-rest x) ))
(defn string-place-typeII
""
[]
(doseq [n (get-placetypes)]
(calculate-distance-matrix 2 (define-context API-KEY) n))
)
(defn calculate-distance-matrix
""
[property-id context place-type]
;(def nearby-search-fucntion )
(let [r (. (. (. (DistanceMatrixApi/newRequest
context)
origins (into-array [(coordinates->keys property-id context)] ))
destinations (into-array [(m/latlng (do-nearby-search property-id context place-type))])) await)]
{:distance (-> r
.rows
first
.elements
first
.distance
.humanReadable)
:duration (-> r
.rows
first
.elements
first
.duration
.humanReadable)})
如何让(string-place-typeII) 在每次迭代中像{:distance "5 km" :duration "2 mins"} 这样返回(calculate-distance-matrix) 的值?
【问题讨论】:
-
你不能用
map代替doseq吗?我只在以下情况下使用doseq1.doseq的主体产生一些副作用,2. 我没有任何东西可以从那里返回
标签: loops google-maps clojure maps