Skip to content

Commit

Permalink
map-of
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Apr 13, 2014
1 parent 160454b commit a79d631
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/compojure/api/common.clj
Expand Up @@ -44,6 +44,12 @@
thus retaining the insertion order. O(n)."
[m k v] (apply array-map (into (vec (apply concat m)) [k v])))

(defmacro map-of
"creates map with symbol names as keywords as keys and
symbol values as values."
[& syms]
`(zipmap ~(vec (map keyword syms)) ~(vec syms)))

;;
;; meta-data-container
;;
Expand Down
2 changes: 1 addition & 1 deletion src/compojure/api/core.clj
Expand Up @@ -183,7 +183,7 @@
body]} (reduce
(fn [acc [k _]]
(or (restructure-param k acc) acc))
{:lets lets :letks letks :parameters parameters :body body}
(map-of lets letks parameters body)
parameters)]
`(~method-symbol
~path
Expand Down
4 changes: 4 additions & 0 deletions test/compojure/api/common_test.clj
Expand Up @@ -64,6 +64,10 @@
(fact "assoc-map-ordered for array-map retains its order"
(keys (reduce (partial apply assoc-map-ordered) (array-map) (map-indexed vector (range 100)))) => (range 100)))

(fact "map-of"
(let [a 1 b true c [:abba :jabba]]
(map-of a b c) => {:a 1 :b true :c [:abba :jabba]}))

(fact "unwrapping meta-container"
(fact "meta-data is returned"
(unwrap-meta-container '(meta-container {:a 1} identity)) => {:a 1})
Expand Down

0 comments on commit a79d631

Please sign in to comment.