Skip to content

Instantly share code, notes, and snippets.

@dball
Created September 7, 2016 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dball/cd2c0b73df3608459f71428f3c9f90f0 to your computer and use it in GitHub Desktop.
Save dball/cd2c0b73df3608459f71428f3c9f90f0 to your computer and use it in GitHub Desktop.
(defn find-dependencies
[system roots]
(let [graph (component/dependency-graph system roots)
dependencies (into #{} (mapcat (:dependencies graph) roots))]
(-> #{}
(into roots)
(into dependencies)
(cond-> (seq dependencies)
(into (find-dependencies system dependencies))))))
(defn sub-system
[system roots]
(let [all (set (keys system))
dependencies (find-dependencies system roots)
unnecessary (disj (set/difference all dependencies) :config)]
(apply dissoc system unnecessary)))
(defn create-system
[config roots decrypters]
(let [dependencies (build-dependencies config)]
(-> (build-system config decrypters)
(component/system-using dependencies)
(sub-system roots))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment