-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
51 lines (46 loc) · 1.95 KB
/
core.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(ns search.core
(:require [schema.core :as s]
[plumbing.graph :as g]
[plumbing.core :refer [fnk defnk]]
[search.schemas :as schemas]
[search.utils :as utils]))
(defnk ->config :- schemas/Config
[graph-symbols
{values {}}
{wrapper-forms []}]
{:graph-symbols graph-symbols
:values values
:wrapper-forms wrapper-forms})
(def compute-search-graph
(g/graph
:default-graph (fnk [graph-symbols values wrapper-forms :as s]
{:id (fnk [] (utils/id))
:config (utils/v->fnk s)
:map-fn (utils/v->fnk map)})
:graphs (fnk [graph-symbols :- [s/Symbol]] (map utils/symbol->value graph-symbols))
:graph (fnk [graphs :- [utils/Graph]] (apply g/graph graphs))
:values-graph (fnk [values :- {s/Keyword s/Any}]
(->> values
(plumbing.core/map-vals utils/eval-load-ns)
(plumbing.core/map-vals utils/v->fnk)
g/graph))
:wrappers (fnk [wrapper-forms :- [schemas/Wrapper]] (map utils/eval-load-ns wrapper-forms))
:wrapper (fnk [wrappers :- [(s/=> utils/Graph utils/Graph)]] (apply comp (reverse wrappers)))
:final-graph (fnk [default-graph :- utils/Graph
graph :- utils/Graph
values-graph :- utils/Graph
wrapper :- (s/=> utils/Graph utils/Graph)]
(-> default-graph
(g/graph graph)
(merge values-graph)
wrapper))
:computed (fnk [final-graph :- schemas/SearchGraph] (g/run final-graph {}))))
(def compute-search (g/compile compute-search-graph))
(s/defn config->generations ; infinite sequence of generations
"Computes the generations for this config. Returns a (possibly infinite)
lazy sequence of generations. The computation happens when you resolve them."
[config :- schemas/Config]
(-> config
compute-search
:computed
:generations))