Skip to content

Commit

Permalink
Add PersistentArrayMap factory, sample maps
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmarczyk committed Apr 29, 2012
1 parent 0812c5c commit 6c29ca5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
:source-path "src/clj/"
:dependencies [[org.clojure/clojure "1.3.0"]
;; locally built from
;; https://github.com/michalmarczyk/clojurescript/tree/reprecating-objmap-2
[org.clojure/clojurescript "0.0-1110"]]
;; https://github.com/michalmarczyk/clojurescript/tree/reprecating-objmap-4
[org.clojure/clojurescript "0.0-1125"]]
:plugins [[lein-cljsbuild "0.1.7"]]
:cljsbuild {:builds [{:source-path "src/cljs/"
:compiler {:output-to "phm.js"
Expand Down
3 changes: 3 additions & 0 deletions src/cljs/phm.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
(defn ^:export empty-persistent-hash-map []
cljs.core.PersistentHashMap/EMPTY)

(defn ^:export empty-persistent-array-map []
cljs.core.PersistentArrayMap/EMPTY)

(defn ^:export assocwrapper [m k v]
(assoc m k v))

Expand Down
39 changes: 39 additions & 0 deletions src/cljs/phm/samples.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(ns phm.samples)

(defn n->m [m n]
(apply assoc m (interleave (range n) (range n))))

(defn n->phm [n]
(n->m cljs.core.PersistentHashMap/EMPTY n))

(defn n->pam [n]
(n->m cljs.core.PersistentArrayMap/EMPTY n))

(defn n->strm [m n]
(apply assoc m (interleave (map (partial str "foo") (range n)) (range n))))

(defn n->strom [n]
(n->strm cljs.core.ObjMap/EMPTY n))

(defn n->strphm [n]
(n->strphm cljs.core.PersistentHashMap/EMPTY n))

(defn n->strpam [n]
(n->strphm cljs.core.PersistentArrayMap/EMPTY n))

(def test-range (range 4 65 4))

(def ^:export phms
(apply js-obj (mapcat (juxt identity n->phm) test-range)))

(def ^:export pams
(apply js-obj (mapcat (juxt identity n->pam) test-range)))

(def ^:export stroms
(apply js-obj (mapcat (juxt identity n->strom) test-range)))

(def ^:export strphms
(apply js-obj (mapcat (juxt identity n->strphm) test-range)))

(def ^:export strpams
(apply js-obj (mapcat (juxt identity n->strpam) test-range)))

0 comments on commit 6c29ca5

Please sign in to comment.