Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

#710 diff mutable sets

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
commit 15c0f015f723f6c7e8ed3b3c88bb1ecfc01e7980 1 parent 9506ca6
Stuart Halloway stuarthalloway authored
15 src/clj/clojure/data.clj
@@ -72,12 +72,19 @@
72 72 java.util.Map
73 73 (equality-partition [x] :map))
74 74
  75 +(defn- as-set-value
  76 + [s]
  77 + (if (set? s) s (into #{} s)))
  78 +
75 79 (extend-protocol Diff
76 80 java.util.Set
77   - (diff-similar [a b]
78   - [(not-empty (set/difference a b))
79   - (not-empty (set/difference b a))
80   - (not-empty (set/intersection a b))])
  81 + (diff-similar
  82 + [a b]
  83 + (let [aval (as-set-value a)
  84 + bval (as-set-value b)]
  85 + [(not-empty (set/difference aval bval))
  86 + (not-empty (set/difference bval aval))
  87 + (not-empty (set/intersection aval bval))]))
81 88
82 89 java.util.List
83 90 (diff-similar [a b]
4 test/clojure/test_clojure/data.clj
@@ -7,7 +7,8 @@
7 7 ; You must not remove this notice, or any other, from this software.
8 8
9 9 (ns clojure.test-clojure.data
10   - (:use clojure.data clojure.test))
  10 + (:use clojure.data clojure.test)
  11 + (import java.util.HashSet))
11 12
12 13 (deftest diff-test
13 14 (are [d x y] (= d (diff x y))
@@ -23,5 +24,6 @@
23 24 [#{:a} #{:b} #{:c :d}] #{:a :c :d} #{:b :c :d}
24 25 [nil nil {:a 1}] {:a 1} {:a 1}
25 26 [{:a #{2}} {:a #{4}} {:a #{3}}] {:a #{2 3}} {:a #{3 4}}
  27 + [#{1} #{3} #{2}] (HashSet. [1 2]) (HashSet. [2 3])
26 28 [{:a {:c [1]}} {:a {:c [0]}} {:a {:c [nil 2] :b 1}}] {:a {:b 1 :c [1 2]}} {:a {:b 1 :c [0 2]}}))
27 29

0 comments on commit 15c0f01

Please sign in to comment.
Something went wrong with that request. Please try again.