Skip to content

Instantly share code, notes, and snippets.

@janherich
Last active January 3, 2016 03:59
Show Gist options
  • Save janherich/8405891 to your computer and use it in GitHub Desktop.
Save janherich/8405891 to your computer and use it in GitHub Desktop.
explicit loop vs for
(def url-sequence (map #(str "http://www.mysite.com/list.php?pageID=" %) (range)))
(def download
(loop [urls url-sequence lst []]
(let [u (first urls)
r (rest urls)
resp (client/get u)
next (re-find #"(s?)title=\"next page\">Next >>" (:body resp))
segments ((html2data (:body resp)) :segment)
data (map segment2data segments)]
(if next
(recur r (conj lst data))
(conj lst data)))))
(def download
(->> (for [url url-sequence
:let [body (:body (client/get url))
next-pages (re-find #"(s?)title=\"next page\">Next >>" body)]
:while next-pages]
(map segment2data (-> body (html2data) (:segment)))))
(into []))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment