Created
May 14, 2014 13:07
-
-
Save tmoerman/fd45a689fcc4c85ba96e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 toggled | |
"Add a toggle to an input channel. | |
The ctrl channel accepts truthy, falsy or :toggle values. | |
The toggle value in the loop determines whether the input value is piped | |
to the output channel or not. | |
_____ | |
=[in]===>| | | |
| alt |=[out]=> | |
=[ctrl]=>| | | |
'-----' | |
" | |
([in ctrl] | |
(toggled in ctrl (chan))) | |
([in ctrl out] | |
(go-loop [toggle true] | |
(alt! in ([v] (if (and v toggle) (>! out v)) | |
(recur toggle)) | |
ctrl ([v] (recur (if (= :toggle v) (not toggle) v))))) | |
out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment