/spread

Macros for building Clojure maps using syntax like JavaScript's shorthand properties and spread syntax.

Primary LanguageCSSEclipse Public License 2.0EPL-2.0

(require '[io.chouser.spread :refer [k.]])

(k. :a "alpha")          ;;=> {:a "alpha"}

(let [b "beta"]
  (k. b, :c "charlie"))  ;;=> {:b "beta" :c "charlie"}

(let [b "beta"
      m {:x 7, :y 9}]
  (k. b, ...m))          ;;=> {:b "beta" :x 7 :y 9}

Mix and match keyword/value pairs, bare symbols, and ellipsis (spread) prefixes to construct a map. Similar to property shorthand and spread syntax in JavaScript Object initializers

The k. macro (a.k.a. keys.) works well for constructing maps that will be destructured with {:keys []}. Also available are strs. and syms. macros for {:strs []} and {:syms []} destructuring respectively.

Thanks to Timothy Pratley for pairing on this!