-
-
Save bhauman/6626683 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
(defn partition-chan | |
([start-pred in] (partition-chan start-pred (complement start-pred) in)) | |
([start-pred end-pred in] | |
(let [out (chan)] | |
(go | |
(loop [] | |
(if-let [val (<! in)] | |
(if (start-pred val) | |
(let [next-chan (chan)] | |
(>! out next-chan) | |
(>! next-chan val) ;; capture the first message | |
(<! (tap-until end-pred in next-chan)) | |
(close! next-chan) | |
(recur))) | |
(close! out)))) | |
out))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment