Last active
November 28, 2016 07:33
-
-
Save halgari/9d9231786e1de196767a 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 batch [max in] | |
(let [out (chan 1)] | |
(go-loop [out-coll []] | |
(when-some [v (<! in)] | |
(let [new-coll (concat out-coll v)] | |
(if (< (count new-coll) max) | |
(recur new-coll) | |
(do (>! out new-coll) | |
(recur new-coll))))) | |
(close! out)) | |
out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment