-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecursion.cue
103 lines (93 loc) · 1.89 KB
/
recursion.cue
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package c4
import (
"list"
)
#RecurseN: {
// this is the bound on our recursion
#maxiter: uint | *8
// This is the function list element
// we generate this to simulate recursion
#funcFactory: {
#next: _
#func: _
}
// this is our "recursion unrolling"
for k, v in list.Range(0, #maxiter, 1) {
// this is where we build up our indexed functions and the references between them
#funcs: "\(k)": (#funcFactory & {#next: #funcs["\(k+1)"]}).#func
}
// our final value needs to be null
#funcs: "\(#maxiter)": null
// we embed the head of the list so that the values
// we write this into can be used like other CUE "functions"
#funcs["0"]
}
#GetAllTech: {
#next: _
#func: {
#in: _
tech: {
for i, x in #in {
if x.technology != _|_ {
"\(x.technology.name)": x.technology
}
if x.systems != _|_ {
(#next & {#in: x.systems}).tech
}
if x.containers != _|_ {
(#next & {#in: x.containers}).tech
}
}
}
}
}
#GetAllElementTags: {
#next: _
#func: {
#in: _
tags: {
for i, x in #in {
if x.tags != _|_ {
for tag in x.tags {
"\(tag.id)": tag
}
}
if x.systems != _|_ {
(#next & {#in: x.systems}).tags
}
if x.containers != _|_ {
(#next & {#in: x.containers}).tags
}
}
}
}
}
#GetAllRelationTags: {
#next: _
#func: {
#in: _
tags: {
for i, x in #in {
if (x & #Relation) != _|_ {
if x.tags != _|_ {
for t in x.tags {
"\(t.id)": t
}
}
}
if x.systems != _|_ {
(#next & {#in: x.systems}).tags
}
if x.containers != _|_ {
(#next & {#in: x.containers}).tags
}
if x.relations != _|_ {
(#next & {#in: x.relations}).tags
}
}
}
}
}
#FoundTechs: #RecurseN & {#funcFactory: #GetAllTech}
#FoundElementTags: #RecurseN & {#funcFactory: #GetAllElementTags}
#FoundRelationTags: #RecurseN & {#funcFactory: #GetAllRelationTags}