Skip to content

Instantly share code, notes, and snippets.

@posobin
Last active November 1, 2019 19:25
Show Gist options
  • Save posobin/4d100029c217c2c9e80e8cd7f9990118 to your computer and use it in GitHub Desktop.
Save posobin/4d100029c217c2c9e80e8cd7f9990118 to your computer and use it in GitHub Desktop.
(defn update-count
[word counter-atom]
(swap! counter-atom update word #(if %1 (inc %1) 1)))
(defn process-quote
[q counter-atom]
(let [quote-words (clojure.string/split q #"\W+")
lowercased-words (map clojure.string/lower-case quote-words)]
(doseq [word lowercased-words]
(update-count word counter-atom))))
(defn quote-word-count
[n-quotes]
(let [word-counter-atom (atom {})]
(->> (map
(fn [_]
(future
(process-quote
(slurp "https://www.braveclojure.com/random-quote")
word-counter-atom)))
(range n-quotes))
doall
(map deref)
doall)
@word-counter-atom))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment