Skip to content

Instantly share code, notes, and snippets.

@halgari
Last active November 28, 2016 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halgari/9d9231786e1de196767a to your computer and use it in GitHub Desktop.
Save halgari/9d9231786e1de196767a to your computer and use it in GitHub Desktop.
(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