Last active
November 1, 2019 19:25
-
-
Save posobin/4d100029c217c2c9e80e8cd7f9990118 to your computer and use it in GitHub Desktop.
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
(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