如何在clojure中实现复合键? [英] How can you implement Composite keys in clojure?

查看:119
本文介绍了如何在clojure中实现复合键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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?

同时...在java中,你可以覆盖等号来为地图制作非常高级的键...如何在clojure中实现复杂的键?

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

推荐答案

您可以使用正确实现equals作为键的任何类型的对象。对于clojure,它包括所有的集合类型,所以你可以只使用一个标准的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

这篇关于如何在clojure中实现复合键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆