开发者

How can you implement Composite keys in clojure?

开发者 https://www.devze.com 2023-04-11 06:40 出处:网络
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 bo开发者_如何学运维th field

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 bo开发者_如何学运维th 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消