Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial Commit

  • Loading branch information...
commit 517bf338983b9237f839bd1b1e2c9445ff4224a2 0 parents
@gigasquid authored
8 .gitignore
@@ -0,0 +1,8 @@
+/pom.xml
+*jar
+/lib
+/classes
+/native
+/.lein-failures
+/checkouts
+/.lein-deps-sum
16 README.md
@@ -0,0 +1,16 @@
+# Baba Yaga Reducers
+
+This is a sample project to explore Clojure Reducers
+[reducers](http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html).
+The code is the basis for a Fairy Tale blog post based on Baba Yaga
+[Blog Post](http://gigasquidsoftware.com/wordpress/?p=409)
+
+
+## Setup instructions
+
+* Download and install [leiningen](https://github.com/technomancy/leiningen)
+* Clone project.
+* You must have Clojure 1.5.0 - [follow these instructions if needed](http://gigasquidsoftware.com/wordpress/?p=403)
+
+
+
15,445 odyssey.txt
15,445 additions, 0 deletions not shown
3  project.clj
@@ -0,0 +1,3 @@
+(defproject reducers "1.0.0-SNAPSHOT"
+ :description "FIXME: write description"
+ :dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]])
34 src/reducers/core.clj
@@ -0,0 +1,34 @@
+(ns reducers.core
+ (:require [clojure.core.reducers :as r]))
+
+(map + [1 2 3]) ;=> (1 2 3)
+(class(map + [1 2 3])) ;=> (1 2 3)
+
+(def odyssey-text (slurp "odyssey.txt"))
+(class odyssey-text) ;=> java.lang.String
+
+(first odyssey-text) ;=> \P
+(class (first odyssey-text)) ;=> java.lang.Character
+(.hashCode (first odyssey-text)) ;=> 80
+(.hashCode (second odyssey-text)) ;=> 114
+(.hashCode (nth odyssey-text 2)) ;=> 111
+
+(defn hashcode [c] (.hashCode c))
+(map hashcode odyssey-text) ;=> (80 114 111..... )
+(filter even? (map hashcode odyssey-text)) ;=> (80 114 ... )
+(reduce + (filter even? (map hashcode odyssey-text))) ;=> 33702446
+
+(dotimes [n 5]
+ (println (str "map - filter - reduce - ( run " n " ):"))
+ (time (reduce + (filter even? (map hashcode odyssey-text)))))
+
+(reduce + (r/filter even? (r/map hashcode odyssey-text))) ;=> 33702446
+
+(dotimes [n 5]
+ (println (str "r/map - r/filter - reduce - ( run " n " ):"))
+ (time (reduce + (r/filter even? (r/map hashcode odyssey-text)))))
+
+(into [] (r/filter even? (r/map hashcode odyssey-text))) ;=> [80 114 ... ]
+
+
+
6 test/reducers/test/core.clj
@@ -0,0 +1,6 @@
+(ns reducers.test.core
+ (:use [reducers.core])
+ (:use [clojure.test]))
+
+(deftest replace-me ;; FIXME: write
+ (is false "No tests have been written."))
Please sign in to comment.
Something went wrong with that request. Please try again.