Skip to content

Commit c103b37

Browse files
committed
fix cljs.reducers-test
- add ObjMapIterator - implement ObjMap IIterable - implement HashMap -kv-reduce - run cljs.reducers-test
1 parent b549ba5 commit c103b37

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12503,6 +12503,15 @@ reduces them without incurring seq initialization"
1250312503
i
1250412504
(recur (+ i incr)))))))
1250512505

12506+
(deftype ObjMapIterator [strkeys strobj ^:mutable i]
12507+
Object
12508+
(hasNext [_]
12509+
(< i (alength strkeys)))
12510+
(next [_]
12511+
(let [k (aget strkeys i)]
12512+
(set! i (inc i))
12513+
(simple-map-entry (obj-map-key->keyword k) (unchecked-get strobj k)))))
12514+
1250612515
(deftype ObjMap [meta strkeys strobj ^:mutable __hash]
1250712516
Object
1250812517
(toString [coll]
@@ -12617,6 +12626,16 @@ reduces them without incurring seq initialization"
1261712626
(recur (rest keys) init)))
1261812627
init))))
1261912628

12629+
IIterable
12630+
(-iterator [coll]
12631+
(ObjMapIterator. strkeys strobj 0))
12632+
12633+
IReduce
12634+
(-reduce [coll f]
12635+
(iter-reduce coll f))
12636+
(-reduce [coll f start]
12637+
(iter-reduce coll f start))
12638+
1262012639
IMap
1262112640
(-dissoc [coll k]
1262212641
(let [k (if-not (keyword? k) k (keyword->obj-map-key k))]
@@ -12847,6 +12866,26 @@ reduces them without incurring seq initialization"
1284712866
(-iterator xs)
1284812867
(nil-iter))))
1284912868

12869+
IKVReduce
12870+
(-kv-reduce [coll f init]
12871+
(let [hashes (.sort (js-keys hashobj))
12872+
ilen (alength hashes)]
12873+
(loop [i 0 init init]
12874+
(if (< i ilen)
12875+
(let [bckt (unchecked-get hashobj (aget hashes i))
12876+
jlen (alength bckt)
12877+
init (loop [j 0 init init]
12878+
(if (< j jlen)
12879+
(let [init (f init (aget bckt j) (aget bckt (inc j)))]
12880+
(if (reduced? init)
12881+
init
12882+
(recur (+ j 2) init)))
12883+
init))]
12884+
(if (reduced? init)
12885+
@init
12886+
(recur (inc i) init)))
12887+
init))))
12888+
1285012889
IPrintWithWriter
1285112890
(-pr-writer [coll writer opts]
1285212891
(print-map coll pr-writer writer opts)))

src/test/cljs/lite_test_runner.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
'cljs.letfn-test
9797
'foo.ns-shadow-test
9898
'cljs.top-level
99-
#_'cljs.reducers-test ;; missing IReduce, IKVReduce
99+
'cljs.reducers-test ;; missing IReduce, IKVReduce
100100
'cljs.keyword-test
101101
'cljs.import-test
102102
'cljs.ns-test.foo

0 commit comments

Comments
 (0)