I have a component that shouldn't run in a dev environment Is there a preferred way for conditionally placing components into the system?
I use a hash-map each for the base system and the deps, and in some cases I merge components conditionally in the maps before starting, in others I dissoc conditionally
the former for optional prod-only things, the latter for special dev-only minimal systems
of course this means using apply instead of directly calling system-map
relevant snippet:
(let [system (virgin-system config-options)
deps (into {}
(filter (fn [[k v]]
(and (contains? system k)
(every? #(contains? system %) (vals v))))
kingfisher-deps))
system (mapcat (fn [[k v :as entry]]
(when (contains? deps k)
entry))
system)]
(-> (apply component/system-map system)
(component/system-using deps)))
this exactly what i needed, thank you!
ya I'd wondered about the system-map
thing, but your apply
solution is perfect
is a hash-map different from a map?
is it that the keys are hashed for faster lookup?
and maps aren't?
no, it's a map (I just say hash-map to differentiate from the function map is all)
oh nice. underneath, the normal map is still a hash map then?
clojure maps technically are either array-maps or hash-maps depending on size, but when they get big enough the array-maps auto-promote to hash-map
ah, thank you
oops, just too small
interesting, clojure really handles a lot of neat things behind the scenes...
thanks for pointing this out!
oh, the other thing is that the virgin-system
function takes a set of keys to dissoc as part of the config - the code I already shared prunes all deps that need those components