Created
February 9, 2018 16:02
-
-
Save theikkila/2127fa6fde8d1f9f01cfce83258ddd68 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
(require '[clojure.core.async :as async :refer [chan go <! >! <!! >!!]]) | |
(defmacro let-go | |
"Like ordinary go-block but first param is symbol for channel thats returned automatically. | |
same as: | |
(let-go c | |
...something with c) | |
-> | |
(let [c (chan)] | |
(go ...something with c) | |
c)" | |
[channel & body] | |
`(let [~channel (chan)] | |
(go ~@body) | |
~channel)) | |
(defn load-lines [path] | |
(let-go c | |
(doseq [f (->> path | |
clojure.java.io/file | |
file-seq | |
(filter #(.isFile %)))] | |
(with-open [rdr (clojure.java.io/reader f)] | |
(doseq [line (line-seq rdr)] | |
(>! c line)))))) | |
(def lines (load-lines "/datasets/testset1")) | |
(<!! lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment