i wasn't able to squeeze that much more out of it, informally maybe around 10% as it gets larger.
(defn- flx ([obj] (flx obj ["$"] {})) ([obj curr res] (cond (map? obj) (reduce #(flx (%2 obj) (conj curr (str "." (name %2))) %1) res (keys obj)) (sequential? obj) (reduce #(flx (second %2) (conj curr (str "[" (first %2) "]")) %1) res (map #(identity (list %1 %2)) (range (count obj)) obj)) :else (assoc res (apply str curr) obj)))) On Tuesday, February 17, 2015 at 11:18:58 AM UTC-5, Mark Watson wrote: > > A slightly cleaner version: > > (defn- flatten-keys* [a ks m] > > (cond > > ;; Is a map? > > (map? m) (reduce into > > (map (fn [[k v]] > > (flatten-keys* a (str ks "." (name k)) v)) > > (seq m))) > > ;; Is an arr/vec/seq? > > (and (sequential? m) > > (not (instance? clojure.lang.MapEntry m))) (reduce into > > (map-indexed (fn > [idx itm] > > > (flatten-keys* a > > > (str ks "[" idx "]") > > > itm)) > > (seq > m))) > > ;; Is not a collection > > :else (assoc a ks m))) > > (defn flatten-keys [m] (flatten-keys* {} "$" m)) > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.