integrant

dharrigan 2019-07-20T19:32:05.000500Z

You know in the example, on the github project page, it has (defmethod ig/init-key :adapter/jetty [_ {:keys [handler] :as opts}] and (defmethod ig/init-key :handler/greet [_ {:keys [name]}]

dharrigan 2019-07-20T19:32:34.001100Z

I can see where the keys part works, but why the don't care placeholder, i.e., _

dharrigan 2019-07-20T19:32:40.001300Z

What would go there?

2019-07-20T20:41:39.001700Z

You could just print it out

dharrigan 2019-07-20T20:42:06.002Z

Yeah, good idea.

dharrigan 2019-07-20T20:43:18.002700Z

it's the key name

dharrigan 2019-07-20T20:45:18.003200Z

or rather, the multimethod dispatch value

dharrigan 2019-07-20T20:46:30.004900Z

so, in the example above (first one), if _ is replaced with foo and then a (println foo), the output will be :adapter/jetty

2019-07-20T20:47:35.005Z

IIRC it will be the argument the method is called with

2019-07-20T20:48:58.005400Z

Or rather the arguments

2019-07-20T20:49:44.006Z

(defmulti ex (fn[x y] (:a x)))
(defmethod ex 2 [x y] (prn 2 x y))
(ex {:a 2 :b 3} {:d 123})
=> 2 {:a 2, :b 3} {:d 123}

dharrigan 2019-07-20T20:50:54.006200Z

ta 🙂

dharrigan 2019-07-20T21:02:23.009800Z

Quite new to this, but if I wanted to share the integrant initialised "system" (by calling (ig/init! config)) an approach would be to store that system in an atom (say my core namespace) then refer to that atom in each of my other namespaces to then obtain the values required (in the other namespace?)

2019-07-20T21:16:00.013500Z

I think the purpose of integrant is to make untangling and encapsulation of a system easier. I think if you need to get something from running system then you, probably, should think twice. But if you really need, you could peek into https://github.com/weavejester/integrant-repl/blob/89a9552fd3623976b83318a5f8f903f1ebeda2f7/src/integrant/repl.clj#L47

dharrigan 2019-07-20T21:19:09.013800Z

Thank you. I'll have a ponder 🙂