Last active
August 29, 2015 14:23
-
-
Save gardnervickers/178f4c4ac0607f6275c5 to your computer and use it in GitHub Desktop.
Read json file and parse to edn with core.async
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 try-parse [x] | |
(try | |
(json/parse-string x true) | |
(catch Exception e | |
x))) | |
(defn lazy-test-data [] | |
"Returns a channel that reads json maps line by line from mock_data.json " | |
(let [channel (chan 5 (map try-parse))] | |
(future (with-open [rdr (clojure.java.io/reader "resources/mock_data.json")] | |
(doseq [line (line-seq rdr)] | |
(>!! channel line))) | |
(>!! channel :done) | |
(close! channel)) | |
channel)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment