Guest User

Untitled

a guest
Nov 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. (ns reducers.core
  2. (:require [clojure.core.reducers :as r]))
  3.  
  4. (map + [1 2 3]) ;=> (1 2 3)
  5. (class(map + [1 2 3])) ;=> (1 2 3)
  6.  
  7. (def odyssey-text (slurp "odyssey.txt"))
  8. (class odyssey-text) ;=> java.lang.String
  9.  
  10. (first odyssey-text) ;=> \P
  11. (class (first odyssey-text)) ;=> java.lang.Character
  12. (.hashCode (first odyssey-text)) ;=> 80
  13. (.hashCode (second odyssey-text)) ;=> 114
  14. (.hashCode (nth odyssey-text 2)) ;=> 111
  15.  
  16. (defn hashcode [c] (.hashCode c))
  17. (map hashcode odyssey-text) ;=> (80 114 111..... )
  18. (filter even? (map hashcode odyssey-text)) ;=> (80 114 ... )
  19. (reduce + (filter even? (map hashcode odyssey-text))) ;=> 33702446
  20.  
  21. (dotimes [n 5]
  22. (println (str "map - filter - reduce - ( run " n " ):"))
  23. (time (reduce + (filter even? (map hashcode odyssey-text)))))
  24.  
  25. (reduce + (r/filter even? (r/map hashcode odyssey-text))) ;=> 33702446
  26.  
  27. (dotimes [n 5]
  28. (println (str "r/map - r/filter - reduce - ( run " n " ):"))
  29. (time (reduce + (r/filter even? (r/map hashcode odyssey-text)))))
Add Comment
Please, Sign In to add comment