Created
August 17, 2013 17:31
-
-
Save lynaghk/6257920 to your computer and use it in GitHub Desktop.
Channel composition; it's fine, but I'm already missing function composition
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 map-into | |
"Forwards `(f (<! recv))` to `send`; returns `send` for convenience." | |
[send f recv] | |
(go (loop [] | |
(let [val (<! recv)] | |
(when-not (nil? val) | |
(>! send (f val)) | |
(recur))))) | |
send) | |
(defn json-deserialization-chan | |
[send recv] | |
(map-into send #(json/parse-string % true) recv)) | |
(defn json-serialization-chan | |
[send recv] | |
(map-into send #(json/generate-string %) recv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment