Skip to content

Instantly share code, notes, and snippets.

@lynaghk
Created August 17, 2013 17:31
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 lynaghk/6257920 to your computer and use it in GitHub Desktop.
Save lynaghk/6257920 to your computer and use it in GitHub Desktop.
Channel composition; it's fine, but I'm already missing function composition
(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