Skip to content

Commit 1452729

Browse files
committed
missing collection protocol method for simple-map-entry
- add ILookup - add IFind - add lite-collection-test for these cases - NOTE: it wasn't clear until we we got to testing that we would need all this stuff. Perhaps we just want to use MapEntry, this does create a dependence on Vector, but I think simple-map-entry was created to avoid the connection to PV before I had done all work to emit the simple vector type under :lite-mode
1 parent 681a507 commit 1452729

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10412,7 +10412,16 @@ reduces them without incurring seq initialization"
1041210412
(-nth [_ i]
1041310413
(case i, 0 k, 1 v, (throw (js/Error. "Index out of bounds"))))
1041410414
(-nth [_ i not-found]
10415-
(case i, 0 k, 1 v, not-found))))
10415+
(case i, 0 k, 1 v, not-found))
10416+
ILookup
10417+
(-lookup [coll k] (-nth coll k nil))
10418+
(-lookup [coll k not-found] (-nth coll k not-found))
10419+
IFind
10420+
(-find [node x]
10421+
(case x
10422+
0 (simple-map-entry 0 k)
10423+
1 (simple-map-entry 1 v)
10424+
nil))))
1041610425

1041710426
(defn- pr-writer-impl
1041810427
[obj writer opts]

src/test/cljs/cljs/lite_collections_test.cljs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,19 @@
3939
(let [a (simple-set [(simple-map-entry 1 2)])]
4040
(is (contains? a (simple-map-entry 1 2)))))
4141

42+
(deftest test-simple-map-entry-lookups
43+
(let [me (simple-map-entry :foo "bar")]
44+
(is (= :foo (get me 0)))
45+
(is (= "bar" (get me 1)))
46+
(is (= [0 :foo]
47+
(vec (find (simple-map-entry :foo "bar") 0))))
48+
(is (= [:foo "b"]
49+
(vec (update (simple-map-entry :foo "bar") 1 first))
50+
(vec (update-in (simple-map-entry :foo "bar") [1] first))))))
51+
4252
(comment
4353

44-
(require '[cljs.lite-collections-test])
54+
(require '[cljs.lite-collections-test] :reload)
4555
(cljs.test/run-tests)
4656

4757
)

0 commit comments

Comments
 (0)