From a12222eac5584e0f2a8c31e770b41aebe65feea9 Mon Sep 17 00:00:00 2001 From: Stephen Rudolph Date: Fri, 12 Feb 2016 16:16:54 -0600 Subject: [PATCH] Persistent queues no longer treated as lists --- src/clj/com/rpl/specter/impl.cljx | 10 +++++++- test/com/rpl/specter/core_test.cljx | 38 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index 55ee39b..9542a7f 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -505,9 +505,17 @@ (defn all-select [structure next-fn] (into [] (r/mapcat next-fn structure))) +#+cljs +(defn queue? [coll] + (= (type coll) (type cljs.core.PersistentQueue/EMPTY))) + +#+clj +(defn queue? [coll] + (= (type coll) (type clojure.lang.PersistentQueue/EMPTY))) + (defn all-transform [structure next-fn] (let [empty-structure (empty structure)] - (cond (list? empty-structure) + (cond (and (list? empty-structure) (not (queue? empty-structure))) ;; this is done to maintain order, otherwise lists get reversed (doall (map next-fn structure)) diff --git a/test/com/rpl/specter/core_test.cljx b/test/com/rpl/specter/core_test.cljx index 596bc93..5f1b745 100644 --- a/test/com/rpl/specter/core_test.cljx +++ b/test/com/rpl/specter/core_test.cljx @@ -740,3 +740,41 @@ (is (= [2 3 [[[4]] :b 0] {:a 4 :b 10}] (s/transform [CustomWalker number?] inc [1 2 [[[3]] :b -1] {:a 3 :b 10}]))) ) + +#+cljs +(defn make-queue [coll] + (reduce + #(conj %1 %2) + cljs.core.PersistentQueue/EMPTY + coll)) + +#+clj +(defn make-queue [coll] + (reduce + #(conj %1 %2) + clojure.lang.PersistentQueue/EMPTY + coll)) + +(defspec transform-idempotency + (for-all+ + [v1 (gen/vector gen/int) + l1 (gen/list gen/int) + m1 (gen/map gen/keyword gen/int)] + (let [s1 (set v1) + q1 (make-queue v1) + v2 (s/transform s/ALL identity v1) + m2 (s/transform s/ALL identity m1) + s2 (s/transform s/ALL identity s1) + l2 (s/transform s/ALL identity l1) + q2 (s/transform s/ALL identity q1)] + (and + (= v1 v2) + (= (type v1) (type v2)) + (= m1 m2) + (= (type m1) (type m2)) + (= s1 s2) + (= (type s1) (type s2)) + (= l1 l2) + (seq? l2) ;; Transformed lists are only guaranteed to impelment ISeq + (= q1 q2) + (= (type q1) (type q2)))))) \ No newline at end of file