Permalink
Browse files

Add IReduce protocol to array and cljs.core.List. Fix typo in reducer…

…s/append!
  • Loading branch information...
1 parent 40899b7 commit 30bb0b9e55fb77cdfe952fbf5df763a25c4a25c5 @danskarda danskarda committed with swannodette May 21, 2013
Showing with 17 additions and 4 deletions.
  1. +10 −2 src/cljs/cljs/core.cljs
  2. +1 −1 src/cljs/clojure/core/reducers.cljs
  3. +6 −1 test/cljs/cljs/reducers_test.cljs
View
@@ -725,7 +725,11 @@ reduces them without incurring seq initialization"
(extend-type array
ICounted
- (-count [a] (alength a)))
+ (-count [a] (alength a))
+
+ IReduce
+ (-reduce [col f] (array-reduce col f))
+ (-reduce [col f start] (array-reduce col f start)))
(declare with-meta)
@@ -1868,7 +1872,11 @@ reduces them without incurring seq initialization"
(-seq [coll] coll)
ICounted
- (-count [coll] count))
+ (-count [coll] count)
+
+ IReduce
+ (-reduce [col f] (seq-reduce f col))
+ (-reduce [col f start] (seq-reduce f start col)))
(deftype EmptyList [meta]
Object
@@ -225,7 +225,7 @@
(defn append!
".adds x to acc and returns acc"
[acc x]
- (doto acc (.add x)))
+ (doto acc (.push x)))
(defn foldcat
"Equivalent to (fold cat append! coll)"
@@ -3,7 +3,12 @@
[clojure.core.reducers :as r]))
(defn test-builtin-impls []
- (assert (= 0 (r/fold + nil))))
+ (assert (= 0 (r/fold + nil)))
+ (assert (= [1 2 3 4] (seq (r/reduce r/append! (r/cat) [1 2 3 4]))))
+ (assert (= 10 (r/reduce + (array 1 2 3 4))))
+ (assert (= 11 (r/reduce + 1 (array 1 2 3 4))))
+ (assert (= 10 (r/reduce + (list 1 2 3 4))))
+ (assert (= 11 (r/reduce + 1 (list 1 2 3 4)))))
(defn test-all []
(test-builtin-impls))

0 comments on commit 30bb0b9

Please sign in to comment.