fix handling of records with ALL in cljs
This commit is contained in:
parent
b66db48a84
commit
b2589e00a6
1 changed files with 30 additions and 23 deletions
|
|
@ -60,6 +60,13 @@
|
||||||
(defn- all-transform-list [structure next-fn]
|
(defn- all-transform-list [structure next-fn]
|
||||||
(doall (sequence (comp (map next-fn) (filter not-NONE?)) structure)))
|
(doall (sequence (comp (map next-fn) (filter not-NONE?)) structure)))
|
||||||
|
|
||||||
|
(defn- all-transform-record [structure next-fn]
|
||||||
|
(reduce
|
||||||
|
(fn [res kv] (conj res (next-fn kv)))
|
||||||
|
structure
|
||||||
|
structure
|
||||||
|
))
|
||||||
|
|
||||||
(extend-protocol AllTransformProtocol
|
(extend-protocol AllTransformProtocol
|
||||||
nil
|
nil
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
|
|
@ -129,13 +136,10 @@
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
(non-transient-map-all-transform structure next-fn (empty structure)))
|
(non-transient-map-all-transform structure next-fn (empty structure)))
|
||||||
|
|
||||||
#?(:clj clojure.lang.IRecord :cljs cljs.core/IRecord)
|
#?(:clj clojure.lang.IRecord)
|
||||||
|
#?(:clj
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
(reduce
|
(all-transform-record structure next-fn)))
|
||||||
(fn [res kv] (conj res (next-fn kv)))
|
|
||||||
structure
|
|
||||||
structure
|
|
||||||
))
|
|
||||||
|
|
||||||
#?(:clj clojure.lang.PersistentHashMap :cljs cljs.core/PersistentHashMap)
|
#?(:clj clojure.lang.PersistentHashMap :cljs cljs.core/PersistentHashMap)
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
|
|
@ -184,25 +188,28 @@
|
||||||
#?(:cljs default)
|
#?(:cljs default)
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
(let [empty-structure (empty structure)]
|
(if (record? structure)
|
||||||
(cond
|
;; this case is solely for cljs since extending to IRecord doesn't work for cljs
|
||||||
(and (list? empty-structure) (not (queue? empty-structure)))
|
(all-transform-record structure next-fn)
|
||||||
(all-transform-list structure next-fn)
|
(let [empty-structure (empty structure)]
|
||||||
|
(cond
|
||||||
|
(and (list? empty-structure) (not (queue? empty-structure)))
|
||||||
|
(all-transform-list structure next-fn)
|
||||||
|
|
||||||
(map? structure)
|
(map? structure)
|
||||||
(reduce-kv
|
(reduce-kv
|
||||||
(fn [m k v]
|
(fn [m k v]
|
||||||
(let [newkv (next-fn [k v])]
|
(let [newkv (next-fn [k v])]
|
||||||
(if (void-transformed-kv-pair? newkv)
|
(if (void-transformed-kv-pair? newkv)
|
||||||
m
|
m
|
||||||
(assoc m (nth newkv 0) (nth newkv 1)))))
|
(assoc m (nth newkv 0) (nth newkv 1)))))
|
||||||
empty-structure
|
empty-structure
|
||||||
structure)
|
structure)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(into empty-structure
|
(into empty-structure
|
||||||
(comp (map next-fn) (filter not-NONE?))
|
(comp (map next-fn) (filter not-NONE?))
|
||||||
structure))))))
|
structure)))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue