Skip to content

Instantly share code, notes, and snippets.

@mbuczko
Created June 28, 2019 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbuczko/6af550aa4f84146ba943849f22f556fd to your computer and use it in GitHub Desktop.
Save mbuczko/6af550aa4f84146ba943849f22f556fd to your computer and use it in GitHub Desktop.
clojure / equal on type
(deftype Employee [name id]
Object
(equals [a b] (= (.id a) (.id b)))
(hashCode [this] (.hashCode (.id this)))
(toString [this] (.name this)))
(def vince (Employee. "Vince" 42))
(def vincent (Employee. "Vincent" 42))
(def tony (Employee. "Tony" 2))
(into #{} [vince vincent tony])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment