Skip to content

Instantly share code, notes, and snippets.

@sritchie
Last active August 29, 2015 14:00
Show Gist options
  • Save sritchie/fddf0c13708f651ef8c3 to your computer and use it in GitHub Desktop.
Save sritchie/fddf0c13708f651ef8c3 to your computer and use it in GitHub Desktop.
(defn flatmap<
"Takes a function and a source channel, and returns a channel which
contains the values in each channel produced by applying f to
each value taken from the source channel. f must return a
channel."
[f in]
(let [out (a/chan)]
(a/go-loop []
(let [item (a/<! in)]
(if (nil? item)
(a/close! out)
(a/pipe (f item) out))))
out))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment