Skip to content

Instantly share code, notes, and snippets.

@mdemare
Forked from richhickey/gist:247172
Created December 3, 2009 20:57
Show Gist options
  • Save mdemare/248515 to your computer and use it in GitHub Desktop.
Save mdemare/248515 to your computer and use it in GitHub Desktop.
;variants of the code from point #2 of:
; http://www.tbray.org/ongoing/When/200x/2009/12/01/Clojure-Theses
;original
(apply merge-with +
(pmap count-lines
(partition-all *batch-size*
(line-seq (reader filename)))))
;pipelined style
(->> (line-seq (reader filename))
(partition-all *batch-size*)
(pmap count-lines)
(apply merge-with +))
;comp style
((comp
(partial apply merge-with +))
(partial pmap count-lines)
(partial partition-all *batch-size*)
line-seq
reader)
filename)
;step-wise, with labeled interim results
(let [lines (line-seq (reader filename))
processed-data (pmap count-lines
(partition-all *batch-size* lines))]
(apply merge-with + processed-data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment