integrant

Ahmed Hassan 2019-07-31T01:04:23.026500Z

What is difference between composite keys and composite references? Purpose is not clear from docs, so I'd like to see some examples.

2019-07-31T01:06:09.028200Z

A composite key is a key derived from a set of keywords. It’s useful when you don’t need an explicit name for a key, you just want a key that’s derived from certain ancestors.

👍 1
2019-07-31T01:08:10.030Z

A composite reference is similar, but from the other direction. A composite reference looks for a key that’s derived from a set of other keys. So you can say, “Find me a key that has an ancestor ::a and an ancestor ::b

👍 1
2019-07-31T01:09:43.031800Z

To give you an example, a composite key [::a ::b] means, “Create a new key that is derived from ::a and ::b“, while a composite ref #ig/ref [::a ::b] means “Find me a key in the map that’s derived from ::a and ::b“.

👍 1
Ahmed Hassan 2019-07-31T01:14:02.032600Z

Are these linked to multimethods in any way?

2019-07-31T01:14:38.032900Z

Only in the same way normal keys are.

Ahmed Hassan 2019-07-31T01:17:47.033Z

So, in this example, does :example/web-1 derives from :adapter/jetty? similar for :example/web-2

2019-07-31T01:19:02.033800Z

No, [:adapter/jetty :example/web-1] derives from :adapter/jetty.

2019-07-31T01:19:14.034100Z

But example/web-1 on its own does not.

Ahmed Hassan 2019-07-31T01:20:38.034600Z

I don't understand what implications does it have.

Ahmed Hassan 2019-07-31T01:21:13.035200Z

It's first time I saw a vector of keywords being derived from a keyword.

2019-07-31T01:21:41.035600Z

Behind the scenes, the vector is being replaced.

2019-07-31T01:22:01.036100Z

So say you had a map {[::a ::b] {:foo 1}}

2019-07-31T01:22:33.036800Z

Actually let’s make it a:

(def config {[::a ::b] {:foo 1}})

2019-07-31T01:23:05.037600Z

It looks for keys that are vectors, and replaces them with a randomly named keyword that derives from the elements in the vector.

2019-07-31T01:23:50.038600Z

(derive ::ab-1232 ::a)
(derive ::ab-1232 ::b)
(def config {::ab-1232 {:foo 1}})

Ahmed Hassan 2019-07-31T01:25:56.039700Z

Thanks a lot. >while a composite ref #ig/ref [::a ::b]means “Find me a key in the map that’s derived from ::a and ::b“. Which map is looked for keys in this case?

2019-07-31T01:26:15.040Z

The same map the ref is in.

2019-07-31T01:26:33.040200Z

The configuration map.

Ahmed Hassan 2019-07-31T01:27:30.041200Z

Ah so, it references already generated composite keys.

2019-07-31T01:27:59.041800Z

Yes, though they don’t have to be composite keys. You could create a key manually and they’d still work, e.g.

2019-07-31T01:28:40.042700Z

(derive ::ab ::a)
(derive ::ab ::b)
(def config {::ab 1, ::c (ig/ref [::a ::b])})

2019-07-31T01:29:10.043400Z

So that would still work, because ::ab is derived from both ::a and ::b. We’ve just derived it explicitly.