Skip to content

Instantly share code, notes, and snippets.

@mhuebert
Created March 7, 2016 18:47
Show Gist options
  • Save mhuebert/0b96b94037acec3e7880 to your computer and use it in GitHub Desktop.
Save mhuebert/0b96b94037acec3e7880 to your computer and use it in GitHub Desktop.
Flat-Map, for multi-path atomic updates in Firebase
(defn flat-map
([m] (clj->js (apply hash-map (flat-map "" m))))
([path m]
(mapcat (fn [[k v]] (if (map? v)
((partial flat-map (str path "/" (name k))) v)
[(str path "/" (name k)) v])) m)))
(= (flat-map {:users {"x0x0x0" {:name "Matt"
:email "[email protected]"}}})
{"users/x0x0x0/name" "Matt"
"users/x0x0x0/email" "[email protected]"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment