File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -8956,6 +8956,7 @@ reduces them without incurring seq initialization"
8956
8956
[proc coll]
8957
8957
(reduce #(proc %2 ) nil coll))
8958
8958
8959
+
8959
8960
(defprotocol IEncodeJS
8960
8961
(-clj->js [x] " Recursively transforms clj values to JavaScript" )
8961
8962
(-key->js [x] " Transforms map keys to valid JavaScript keys. Arbitrary keys are
@@ -9610,3 +9611,40 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
9610
9611
(if f
9611
9612
(do (f ) :ok )
9612
9613
:no-test )))
9614
+
9615
+
9616
+ (deftype TaggedLiteral [tag form]
9617
+
9618
+ IEquiv
9619
+ (-equiv [this other]
9620
+ (and (instance? TaggedLiteral other)
9621
+ (= tag (.-tag other))
9622
+ (= form (.-form other))))
9623
+
9624
+ IHash
9625
+ (-hash [this]
9626
+ (+ (* 31 (hash tag))
9627
+ (hash form)))
9628
+
9629
+ ILookup
9630
+ (-lookup [this v]
9631
+ (-lookup this v nil ))
9632
+ (-lookup [this v not-found]
9633
+ (case v
9634
+ :tag tag
9635
+ :form form
9636
+ not-found))
9637
+
9638
+ )
9639
+
9640
+ (defn tagged-literal?
9641
+ " Return true if the value is the data representation of a tagged literal"
9642
+ [value]
9643
+ (instance? cljs.core.TaggedLiteral value))
9644
+
9645
+ (defn tagged-literal
9646
+ " Construct a data representation of a tagged literal from a
9647
+ tag symbol and a form."
9648
+ [tag form]
9649
+ {:pre (symbol? tag)}
9650
+ (cljs.core.TaggedLiteral. tag form))
Original file line number Diff line number Diff line change 2793
2793
(is (= (-> #'map meta :arglists )
2794
2794
'([f] [f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]))))
2795
2795
2796
+ (deftest tagged-literals
2797
+ (let [tl (tagged-literal 'x " y" )]
2798
+ (is (tagged-literal? tl))
2799
+ (is (not (tagged-literal? {:tag 'x :form " y" })))
2800
+ (is (= (:tag tl) 'x))
2801
+ (is (= (:form tl) " y" ))
2802
+ (is (= tl (tagged-literal 'x " y" )))
2803
+ (is (not= tl (tagged-literal 'z " y" )))
2804
+ (is (not= tl (tagged-literal 'x " z" )))
2805
+ (is (= (hash tl) (hash (tagged-literal 'x " y" ))))))
2806
+
2796
2807
(comment
2797
2808
; ; ObjMap
2798
2809
; ; (let [ks (map (partial str "foo") (range 500))
You can’t perform that action at this time.
0 commit comments