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

View File

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