Skip to content

Instantly share code, notes, and snippets.

@bhb
Last active June 8, 2017 14:56
An case (admittedly, a corner case) where two values are equal, but are not equally valid
;; Admittedly, this is a weird spec designed to trigger this case.
;; I'm not sure if there are cases where this would realistically happen
(require '[clojure.spec.alpha :as s])
(s/def :test/pairs (s/cat :p1 (s/spec (s/cat :k keyword? :v pos-int?)) :p2 any?))
(let [m1 {:b -1 :a 1}
m2 {:a 1 :b -1}]
{:equal? (= (m1 m2))
:equally-valid? (=
(s/valid? :test/pairs m1)
(s/valid? :test/pairs m2))})
;; returns
;; {:equal? true, :equally-valid? false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment