Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
(ns my-wide-finder "A basic map/reduce approach to the wide finder using agents. Optimized for being idiomatic and readable rather than speed. NOTE: Originally from: http://technomancy.us/130 but updated to use pmap." (:use [clojure.contrib.duck-streams :only [reader read-lines]])) (def re #"GET /(\d+) ") (defn count-line "Increment the relevant entry in the counts map." [line] (if-let [[_ hit] (re-find re line)] {hit 1} {})) (defn count-lines "Grab a chunk of lines and ..." [seq] (apply merge-with + (map count-line (take 20 seq)))) (defn my-find-widely "Return a map of pages to hit counts in filename." [filename] (apply merge-with + (pmap count-lines (line-seq (reader filename)))))
This paste will be private.
From the Design Piracy series on my blog: