Skip to content

Instantly share code, notes, and snippets.

@spacepluk
Created September 4, 2016 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spacepluk/f20fc43fb702cf25d654e2fd0d86e058 to your computer and use it in GitHub Desktop.
Save spacepluk/f20fc43fb702cf25d654e2fd0d86e058 to your computer and use it in GitHub Desktop.
(defn seq!!
"Returns a (blocking!) lazy sequence read from a channel."
[c]
(lazy-seq
(when-let [v (<!! c)]
(cons v (seq!! c)))))
(defn -main
[& args]
(let [c (chan)]
(future
(doseq [i (range 10)]
(>!! c i))
(close! c))
(doseq [s (seq!! c)]
(println s)))
(println "exit"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment