Last active
December 21, 2015 04:48
-
-
Save swannodette/6251850 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 tapify [f & args] | |
(as-> (chan) in | |
{:in in | |
:out (apply f in args)})) | |
(defn switch | |
([in taps control] (switch taps control (chan))) | |
([in taps control out] | |
(go (loop [n -1] | |
(let [[v c] (alts! [control in])] | |
(if (= c control) | |
(recur v) | |
(do | |
(if (not= n -1) | |
(do | |
(>! (:in (taps n)) v) | |
(>! out (<! (:out (taps n))))) | |
(>! out v)) | |
(recur n)))))) | |
out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment