Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you implement Composite keys in clojure?

Tags:

clojure

How can you implement Composite keys in clojure? If I have a map where First and last name, for example, point to a list of attributes .... Could I make a map that contained both fields as the key?

And meanwhile ... In java you can override "equals" to make very advanced keys for maps... How are sophisticated keys implemented in clojure?

like image 380
jayunit100 Avatar asked Oct 06 '11 05:10

jayunit100


1 Answers

You can use any kind of object that correctly implements equals as a key. For clojure, that includes all the collection types, so you can just use a standard clojure collection as the key. Example using a two-element vectors as keys:

(def foo {[1 2] :bar [3 4] :baz})
=> #'user/foo
(foo [1 2])
=> :bar
like image 57
Joost Diepenmaat Avatar answered Nov 15 '22 09:11

Joost Diepenmaat