Created
July 23, 2014 17:40
-
-
Save rxacevedo/6cb89e07f700b9c30bdc to your computer and use it in GitHub Desktop.
Monoids, reducers, map, etc.
This file contains hidden or 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
| (require '[clojure.core.reducers :as rd]) | |
| ;; => nil | |
| (letfn [(monoid-mapping [f] | |
| (rd/monoid | |
| (fn [l r] (conj l (f r))) vector)) | |
| (monoid-reducer-map [f coll] | |
| (reduce (monoid-mapping f) | |
| ((monoid-mapping f)) | |
| coll))] | |
| (do | |
| (println (monoid-reducer-map inc (range 10))) | |
| (println (monoid-reducer-map #(.toUpperCase %) ["wind it up" | |
| "f*** you and yo bassline" | |
| "turn down for what"])))) | |
| ; [1 2 3 4 5 6 7 8 9 10] | |
| ; [WIND IT UP F*** YOU AND YO BASSLINE TURN DOWN FOR WHAT] | |
| ;; => nil |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work gracefully on maps because
monoid-mappingusesvectoras the identity.