-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
interfaces.clj
27 lines (23 loc) · 1.17 KB
/
interfaces.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(ns polylith.clj.core.workspace.interfaces)
(defn ->interface [[_ [{:keys [name interface]}]]]
{:name (:name interface)
:type "interface"
:definitions (:definitions interface)
:implementing-components [name]})
(defn params [parameters]
(mapv :name parameters))
(defn ->multi-interface [[interface-name components]]
{:name interface-name
:type "interface"
:definitions (vec (sort-by (juxt :sub-ns :type :name params)
(set (mapcat #(-> % :interface :definitions) components))))
:implementing-components (vec (sort (map :name components)))})
(defn calculate [components]
"Calculates all interfaces, which are all definitions (data/function/macro)
that are defined for all components that implements an interface."
(let [grouped-components (group-by #(-> % :interface :name) components)
single-components (filter #(= (-> % second count) 1) grouped-components)
multi-components (filter #(> (-> % second count) 1) grouped-components)
single-interfaces (mapv ->interface single-components)
multi-interfaces (map ->multi-interface multi-components)]
(vec (concat single-interfaces multi-interfaces))))