Skip to content

Instantly share code, notes, and snippets.

@theikkila
Created February 9, 2018 16:02
Show Gist options
  • Save theikkila/2127fa6fde8d1f9f01cfce83258ddd68 to your computer and use it in GitHub Desktop.
Save theikkila/2127fa6fde8d1f9f01cfce83258ddd68 to your computer and use it in GitHub Desktop.
(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