Created
May 20, 2014 13:09
-
-
Save gfredericks/2f6d21890bbe82ed5416 to your computer and use it in GitHub Desktop.
seque implemented 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 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