Clojure lazy seq consumption from different positions in the function body

Clojure, a beginner here, is not sure the terminology in the question is even correct.

I am building a web scraper using taxi api for clj-webdriver. There are several sites that need to be cleaned up. The following code is not really the code from the project, but I tested it and confirmed that it illustrates my question:

(def gh-un "my-username")
(def gh-pw "my-password")

;; print the first five "starred" alerts from my github feed
(defn get-info [url]
  (to url)
  (click "a[href='/login']")
  (input-text "input#login_field" gh-un)
  (input-text "input#password" gh-pw)
  (click "input.btn")
  (pprint (map text (take 5 (find-elements {:css "div.alert.watch_started"}))))
  (click "img.avatar")
  (click "button.dropdown-signout"))

(defn github-wrapper []
  (map get-info (repeat 3 "http://www.github.com"))
  (quit))

If I call (github-wrapper)as is, the browser window will close almost immediately, due to the call (quit). Call wrapper mapwith doall, i.e. (doall (map get-info (repeat 3 "http://www.github.com"))), solves this problem, which suggests that the problem is that the card creates a lazy sequence that is not consumed, and therefore I do not see any side effects get-info.

, (quit) get-info, github-wrapper , .

: , ?

+4
1

, , , github-wrapper. - ( doall), . quit github-wrapper, , , , .

mapv map, , .

+1
source

Source: https://habr.com/ru/post/1625655/


All Articles