Commits

Meikel Brandmeyer committed 56bcc35

Use clojure.contrib.fcase in LazyMap

* lazymap.clj (cons): use instance-case to get rid of cond/instance? pairs

  • Participants
  • Parent commits 9a5b358

Comments (0)

Files changed (1)

File src/de/kotka/lazymap/LazyMap.clj

                     clojure.lang.IObj]
      :constructors {[clojure.lang.IPersistentMap] []})
   (:import
-     (clojure.lang SeqIterator IMapEntry IPersistentVector IObj)))
+     (clojure.lang SeqIterator IMapEntry IPersistentVector IObj))
+  (:use
+     [clojure.contrib.fcase :only (instance-case)]))
 
 (defn- -init
   [theMap]
 
 (defn- -cons
   [this o]
-  (cond
-    (instance? de.kotka.lazymap.LazyMapEntry o) (let [k (. o getKey)
-                                     v (. o getRawValue)]
-                                 (. this lazyAssoc k v))
-    (instance? IMapEntry o)    (let [k (. o getKey)
-                                     v (. o getValue)]
-                                 (. this assoc k (delay v)))
-    (instance? IPersistentVector o)
-                               (if (= (count o) 2)
-                                 (let [k (o 0)
-                                       v (o 1)]
-                                   (. this assoc k (delay v)))
-                                 (throw (new IllegalArgumentException
-                                             "Vector arg to map conj must be a pair")))
-    :else                      (reduce #(. %1 cons %2) this o)))
+  (instance-case o
+    de.kotka.lazymap.LazyMapEntry
+                      (let [k (. o getKey)
+                            v (. o getRawValue)]
+                        (. this lazyAssoc k v))
+    IMapEntry         (let [k (. o getKey)
+                            v (. o getValue)]
+                        (. this assoc k (delay v)))
+    IPersistentVector (if (= (count o) 2)
+                        (let [k (o 0)
+                              v (o 1)]
+                          (. this assoc k (delay v)))
+                        (throw (new IllegalArgumentException
+                                    "Vector arg to map conj must be a pair")))
+    (reduce #(. %1 cons %2) this o)))
 
 (defn- -empty
   [this]