/map-crusher

Turn nested Clojure maps into a flat map

Primary LanguageClojureEclipse Public License 2.0EPL-2.0

map-crusher

Clojars Project

Turns a nested Clojure map into a flat (deps=1) map with concatenated attributes representing the original nesting.

Usage

(requre '[iku000888.map.crusher :refer [crush])
(crush {:foo {:bar ["baz"]}
        :works {:with [:values :in :seq :if :primitive]}})

=>
{:foo.bar ("baz"),
 :works.with (:values :in :seq :if :primitive)}

Caveat

This 'works' on nested vector values with the assumption that the values in the vector is homogenous. In particular the result at a glance may not conform to intuition if the algorithm encounters something like this. However, this is by design to only contain primitive or seq of primitive values in the resulting map. (Otherwise the result is a nested map.)

  (crush {:weird [:looking
                  {:if {:mix [:match :primitives {:in :seq}]}}]})
=>
{:weird.if.mix.in (:seq),
 :weird.if.mix (:match :primitives),
 :weird (:looking)}