finish implementation of #117
This commit is contained in:
parent
6b500a6aef
commit
00ab106dd6
1 changed files with 18 additions and 9 deletions
|
|
@ -72,6 +72,17 @@
|
||||||
empty-map
|
empty-map
|
||||||
structure))
|
structure))
|
||||||
|
|
||||||
|
(defn not-NONE? [v]
|
||||||
|
(-> v (identical? i/NONE) not))
|
||||||
|
|
||||||
|
|
||||||
|
(defn- all-transform-list [structure next-fn]
|
||||||
|
;; this is done to maintain order, otherwise lists get reversed
|
||||||
|
(->> structure
|
||||||
|
(into '()
|
||||||
|
(comp (map next-fn) (filter not-NONE?)))
|
||||||
|
reverse
|
||||||
|
))
|
||||||
|
|
||||||
(extend-protocol AllTransformProtocol
|
(extend-protocol AllTransformProtocol
|
||||||
nil
|
nil
|
||||||
|
|
@ -92,7 +103,7 @@
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
(into []
|
(into []
|
||||||
(comp (map next-fn)
|
(comp (map next-fn)
|
||||||
(filter #(-> % (identical? i/NONE) not)))
|
(filter not-NONE?))
|
||||||
structure))
|
structure))
|
||||||
|
|
||||||
#?(:clj clojure.lang.PersistentArrayMap)
|
#?(:clj clojure.lang.PersistentArrayMap)
|
||||||
|
|
@ -158,9 +169,7 @@
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
(let [empty-structure (empty structure)]
|
(let [empty-structure (empty structure)]
|
||||||
(cond (and (list? empty-structure) (not (queue? empty-structure)))
|
(cond (and (list? empty-structure) (not (queue? empty-structure)))
|
||||||
;; this is done to maintain order, otherwise lists get reversed
|
(all-transform-list structure next-fn)
|
||||||
;;TODO: need to handle NONE here
|
|
||||||
(doall (map next-fn structure))
|
|
||||||
|
|
||||||
(map? structure)
|
(map? structure)
|
||||||
;; reduce-kv is much faster than doing r/map through call to (into ...)
|
;; reduce-kv is much faster than doing r/map through call to (into ...)
|
||||||
|
|
@ -178,19 +187,19 @@
|
||||||
:else
|
:else
|
||||||
(->> structure
|
(->> structure
|
||||||
(r/map next-fn)
|
(r/map next-fn)
|
||||||
(r/filter #(-> % (identical? i/NONE) not))
|
(r/filter not-NONE?)
|
||||||
(into empty-structure))))))
|
(into empty-structure))))))
|
||||||
|
|
||||||
|
|
||||||
#?(:cljs default)
|
#?(:cljs default)
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
;;TODO: need to handle NONE here
|
|
||||||
(let [empty-structure (empty structure)]
|
(let [empty-structure (empty structure)]
|
||||||
(if (and (list? empty-structure) (not (queue? empty-structure)))
|
(if (and (list? empty-structure) (not (queue? empty-structure)))
|
||||||
;; this is done to maintain order, otherwise lists get reversed
|
(all-transform-list structure next-fn)
|
||||||
(doall (map next-fn structure))
|
(into empty-structure
|
||||||
(into empty-structure (map #(next-fn %)) structure))))))
|
(comp (map next-fn) (filter not-NONE?))
|
||||||
|
structure))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue