Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created May 20, 2014 13:09
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 gfredericks/2f6d21890bbe82ed5416 to your computer and use it in GitHub Desktop.
Save gfredericks/2f6d21890bbe82ed5416 to your computer and use it in GitHub Desktop.
seque implemented with core.async
(defn seque
[n s]
(let [ch (async/chan n)]
(async/go-loop [s s]
(try
(if-let [[x & xs] (seq s)]
(do (async/>! ch (list x))
(recur xs))
(async/close! ch))
(catch Throwable t
(async/>! ch t)
(async/close! ch))))
((fn f []
(lazy-seq
(if-let [x (async/<!! ch)]
(if (instance? Throwable x)
(throw x)
(cons (first x) (f)))
()))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment