Skip to content

Instantly share code, notes, and snippets.

@slipset
Created April 15, 2019 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slipset/12af01dfac0632d4dbe40a32d96b9e8c to your computer and use it in GitHub Desktop.
Save slipset/12af01dfac0632d4dbe40a32d96b9e8c to your computer and use it in GitHub Desktop.
(def urls {:vg "https://www.vg.no", :ap "https://www.ap.no", :db "https://www.db.no"} )
(defn my-get-request [[k url]]
[k (future (http/get url))])
(->> urls
(map my-get-request)
(reduce (fn [acc [k v]]
(assoc acc k (deref v))) {}))
@slipset
Copy link
Author

slipset commented Apr 15, 2019

(defn my-get [i]
  [i (future (:status (http/get "https://www.vg.no")))])

(defn transmogrify [acc [k v]]
  (let [t (System/currentTimeMillis)
        v' (deref v)]
    (println "Spent " (- (System/currentTimeMillis) t) "ms dreffing" k)
    (assoc acc k v')))

(->> (range 100)
     (reduce (fn [acc i] (conj acc (my-get i))) [])
     (reduce transmogrify {}))

does the thing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment