Last active
August 29, 2015 14:00
-
-
Save sritchie/fddf0c13708f651ef8c3 to your computer and use it in GitHub Desktop.
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 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