1 | static L<Concept> unrollOptions(Concept c) { |
2 | if (c << Options) |
3 | ret concatMap("unrollOptions", c/Options); |
4 | if (!conceptHasOptions(c)) |
5 | ret ll(c); |
6 | else { // c has Options hidden somewhere within - recurse & "multiply" |
7 | new Map<S, O> simples; |
8 | Map<S, L<Concept>> multiples = new TreeMap; |
9 | |
10 | for (S field : conceptFields(c)) { |
11 | O val = cget(c, field); |
12 | if (!val << Concept) |
13 | simples.put(field, val); |
14 | else { |
15 | L<Concept> l = unrollOptions(val/Concept); |
16 | if (empty(l)) ret ll(); |
17 | else if (l(l) == 1) |
18 | simples.put(field, first(l)); |
19 | else |
20 | multiples.put(field, l); |
21 | } |
22 | } |
23 | |
24 | final Concept d = unlisted(c.getClass()); |
25 | csetMap(d, simples); |
26 | |
27 | if (empty(multiples)) |
28 | ret ll(d); |
29 | else { |
30 | if (l(multiples) > 2) warn("todo johnny"); |
31 | new L out; |
32 | L<S> fields = asList(keys(multiples)); |
33 | |
34 | S field0 = fields.get(0); |
35 | for (Concept value0 : multiples.get(field0)) { |
36 | Concept e = unlisted(c.getClass()); |
37 | copyConceptFields(d, e); |
38 | cset(e, field0, value0); |
39 | if (l(multiples) == 1) out.add(e); else { |
40 | S field1 = fields.get(1); |
41 | for (Concept value1 : multiples.get(field1)) { |
42 | Concept f = unlisted(c.getClass()); |
43 | copyConceptFields(e, f); |
44 | cset(f, field1, value1); |
45 | out.add(f); |
46 | } |
47 | } |
48 | } |
49 | ret out; |
50 | } |
51 | } |
52 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005496 |
Snippet name: | unrollOptions |
Eternal ID of this version: | #1005496/1 |
Text MD5: | 5a02d0e2cba61ec37eb10c1c0e2ba296 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-11-23 14:51:08 |
Source code size: | 1508 bytes / 52 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 502 / 525 |
Referenced in: | [show references] |