component

2017-04-05T22:55:56.342841Z

I have a component that shouldn't run in a dev environment Is there a preferred way for conditionally placing components into the system?

2017-04-05T22:57:06.355814Z

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

2017-04-05T22:57:23.359141Z

the former for optional prod-only things, the latter for special dev-only minimal systems

2017-04-05T22:59:09.378241Z

of course this means using apply instead of directly calling system-map

2017-04-05T22:59:46.385231Z

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)))

2017-04-05T23:00:18.391912Z

this exactly what i needed, thank you!

2017-04-05T23:00:36.396043Z

ya I'd wondered about the system-map thing, but your apply solution is perfect

2017-04-05T23:00:55.399591Z

is a hash-map different from a map?

2017-04-05T23:01:04.401398Z

is it that the keys are hashed for faster lookup?

2017-04-05T23:01:09.402269Z

and maps aren't?

2017-04-05T23:01:19.404221Z

no, it's a map (I just say hash-map to differentiate from the function map is all)

2017-04-05T23:01:40.408184Z

oh nice. underneath, the normal map is still a hash map then?

2017-04-05T23:02:12.414110Z

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

2017-04-05T23:02:49.421177Z

ah, thank you

2017-04-05T23:03:08.424678Z

oops, just too small

2017-04-05T23:04:07.435500Z

interesting, clojure really handles a lot of neat things behind the scenes...

2017-04-05T23:04:11.436154Z

thanks for pointing this out!

2017-04-05T23:18:04.583646Z

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