Reduce is great. Use it more

This commit is contained in:
Dan Holmsand 2014-02-11 12:41:00 +01:00
parent b041427e94
commit 41962bbe18
2 changed files with 18 additions and 15 deletions

View File

@ -149,9 +149,10 @@
(def obligatory {:shouldComponentUpdate nil (def obligatory {:shouldComponentUpdate nil
:componentWillUnmount nil}) :componentWillUnmount nil})
(defn camelify-map-keys [m] (defn camelify-map-keys [fun-map]
(into {} (for [[k v] m] (reduce-kv (fn [m k v]
[(-> k tmpl/dash-to-camel keyword) v]))) (assoc m (-> k tmpl/dash-to-camel keyword) v))
{} fun-map))
(defn add-obligatory [fun-map] (defn add-obligatory [fun-map]
(merge obligatory fun-map)) (merge obligatory fun-map))
@ -178,8 +179,9 @@
fmap (-> fun-map fmap (-> fun-map
(assoc :displayName name') (assoc :displayName name')
(add-render render-fun))] (add-render render-fun))]
(into {} (for [[k v] fmap] (reduce-kv (fn [m k v]
[k (get-wrapper k v name')])))) (assoc m k (get-wrapper k v name')))
{} fmap)))
(defn map-to-js [m] (defn map-to-js [m]
(reduce-kv (fn [o k v] (reduce-kv (fn [o k v]

View File

@ -154,14 +154,15 @@
(defn equal-args [v1 v2] (defn equal-args [v1 v2]
;; Compare two vectors using identical? ;; Compare two vectors using identical?
(assert (vector? v1))
(assert (vector? v2))
(or (identical? v1 v2) (or (identical? v1 v2)
(let [end (count v1)] (and (== (count v1) (count v2))
(and (== end (count v2)) (reduce-kv (fn [res k v]
(loop [n 1] (let [v' (v2 k)]
(if (>= n end) (if (or (identical? v v')
true (and (== 1 k)
(if (or (identical? (v1 n) (v2 n)) (shallow-equal-maps v v')))
(and (== 1 n) res
(shallow-equal-maps (v1 1) (v2 1)))) (reduced false))))
(recur (inc n)) true v1))))
false)))))))