-
-
Save fatfingererr/e9ad55cd7b8dbdfbef97c61fb9929880 to your computer and use it in GitHub Desktop.
map-reduce in hylang
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
; Packed shepherd together with mincemeat for convenience | |
(import [mincemeat.shepherd [run_server]]) | |
; chunker is temporarily broken | |
;(defn chunker [gen size] | |
; (let [[gen (iter gen)] | |
; [chunk []] | |
; (try | |
; (while True | |
; (for [_ (xrange size)] | |
; (.append chunk (.next gen)) | |
; (yield chunk) | |
; (setv chunk []))) | |
; (catch [e StopIteration] | |
; (if chunk | |
; (yield chunk)))))) | |
(def datasource (dict (enumerate (open "chekhov.txt" "r")))) | |
(defn mapfn [k v] | |
(for [w (.split v)] | |
(yield (, (.lower w) 1)))) | |
(defn reducefn [k vs] | |
(sum vs)) | |
(print (run_server | |
{ "datasource" datasource | |
"mapfn" mapfn | |
"reducefn" reducefn })) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment