Last active
January 3, 2016 03:59
-
-
Save janherich/8405891 to your computer and use it in GitHub Desktop.
explicit loop vs for
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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