Skip to content

Instantly share code, notes, and snippets.

@swannodette
Last active December 21, 2015 04:48
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 swannodette/6251850 to your computer and use it in GitHub Desktop.
Save swannodette/6251850 to your computer and use it in GitHub Desktop.
(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