Moving CLJS code to use transformers instead of reducers
This commit is contained in:
parent
0f2118d939
commit
ddea0a223d
1 changed files with 24 additions and 1 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
[select* transform* collect-val]])
|
[select* transform* collect-val]])
|
||||||
(:require [com.rpl.specter.protocols :as p]
|
(:require [com.rpl.specter.protocols :as p]
|
||||||
[clojure.walk :as walk]
|
[clojure.walk :as walk]
|
||||||
[clojure.core.reducers :as r]
|
#+clj [clojure.core.reducers :as r]
|
||||||
[clojure.string :as s]
|
[clojure.string :as s]
|
||||||
#+clj [com.rpl.specter.defhelpers :as dh]
|
#+clj [com.rpl.specter.defhelpers :as dh]
|
||||||
)
|
)
|
||||||
|
|
@ -502,9 +502,18 @@
|
||||||
(assoc structure akey (next-fn (get structure akey))
|
(assoc structure akey (next-fn (get structure akey))
|
||||||
))
|
))
|
||||||
|
|
||||||
|
#+clj
|
||||||
(defn all-select [structure next-fn]
|
(defn all-select [structure next-fn]
|
||||||
(into [] (r/mapcat next-fn structure)))
|
(into [] (r/mapcat next-fn structure)))
|
||||||
|
|
||||||
|
#+cljs
|
||||||
|
(defn next-fn-mapcat-transformation [next-fn]
|
||||||
|
(mapcat #(next-fn %1)))
|
||||||
|
|
||||||
|
#+cljs
|
||||||
|
(defn all-select [structure next-fn]
|
||||||
|
(into [] (next-fn-mapcat-transformation next-fn) structure))
|
||||||
|
|
||||||
#+cljs
|
#+cljs
|
||||||
(defn queue? [coll]
|
(defn queue? [coll]
|
||||||
(= (type coll) (type #queue [])))
|
(= (type coll) (type #queue [])))
|
||||||
|
|
@ -513,6 +522,7 @@
|
||||||
(defn queue? [coll]
|
(defn queue? [coll]
|
||||||
(= (type coll) (type clojure.lang.PersistentQueue/EMPTY)))
|
(= (type coll) (type clojure.lang.PersistentQueue/EMPTY)))
|
||||||
|
|
||||||
|
#+clj
|
||||||
(defn all-transform [structure next-fn]
|
(defn 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)))
|
||||||
|
|
@ -526,6 +536,19 @@
|
||||||
(->> structure (r/map next-fn) (into empty-structure))
|
(->> structure (r/map next-fn) (into empty-structure))
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
#+cljs
|
||||||
|
(defn next-fn-map-transformation [next-fn]
|
||||||
|
(map #(next-fn %1)))
|
||||||
|
|
||||||
|
#+cljs
|
||||||
|
(defn all-transform [structure next-fn]
|
||||||
|
(let [empty-structure (empty structure)]
|
||||||
|
(if (and (list? empty-structure) (not (queue? empty-structure)))
|
||||||
|
;; this is done to maintain order, otherwise lists get reversed
|
||||||
|
(doall (map next-fn structure))
|
||||||
|
(into empty-structure (next-fn-map-transformation next-fn) structure)
|
||||||
|
)))
|
||||||
|
|
||||||
(deftype AllStructurePath [])
|
(deftype AllStructurePath [])
|
||||||
|
|
||||||
(extend-protocol p/StructurePath
|
(extend-protocol p/StructurePath
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue