Permalink
Browse files

cons apparently needs to work with tuples and maps

  • Loading branch information...
1 parent d3e5aa2 commit 0d209a87ad855278bba9c33cd6baf16b59dce2c1 @ztellman committed Aug 8, 2012
Showing with 11 additions and 14 deletions.
  1. +5 −12 src/potemkin/map.clj
  2. +6 −2 test/potemkin/test/map.clj
View
@@ -62,9 +62,11 @@
(map? x)
(= x (into {} this))))
(cons [this o]
- (if-let [[k v] (seq o)]
- (assoc this k v)
- this))
+ (if (map? o)
+ (reduce #(apply assoc %1 %2) this o)
+ (if-let [[k v] (seq o)]
+ (assoc this k v)
+ this)))
clojure.lang.Counted
(count [this]
@@ -85,15 +87,6 @@
[this f val#]
(reduce f val# (seq this)))))
- ;; clojure.core.protocols.CollReduce
- ;; (coll-reduce
- ;; [this f]
- ;; (reduce f (seq this)))
-
- ;; (coll-reduce
- ;; [this f val#]
- ;; (reduce f val# (seq this)))
-
Object
(hashCode [this]
(reduce
@@ -46,6 +46,12 @@
(is (= [:a] (keys m)))
(is (= [[:a 1]] (seq m))))
+ (let [m (assoc m :a 1)]
+ (is (= {:a 1, :b 2, :c 3}
+ (merge m {:b 2} {:c 3})
+ (merge m {:b 2, :c 3})
+ (merge {:b 2, :c 3} m))))
+
(let [m (-> m (assoc :a 1) (dissoc :a))]
(is (not (contains? m :a))))
@@ -66,5 +72,3 @@
(deftest test-maps
(test-basic-map-functionality (SimpleMap. {}))
(test-basic-map-functionality (SimpleOverrides. {})))
-
-

0 comments on commit 0d209a8

Please sign in to comment.