1 | // f : Concept -> Concept |
2 | static Concept conceptGraphMap(Concept c, O f) { |
3 | ret conceptGraphMap_impl(c, f, new IdentityHashMap); |
4 | } |
5 | |
6 | static Concept conceptGraphMap_impl(Concept c, O f, IdentityHashMap<Concept, Concept> seen) { |
7 | if (seen.containsKey(c)) |
8 | ret seen.get(c); |
9 | Concept d = cast callF(f, c); |
10 | if (d != c) { |
11 | seen.put(c, d); |
12 | ret d; |
13 | } |
14 | |
15 | d = cnew(c.getClass()); |
16 | seen.put(c, d); |
17 | |
18 | for (S field : conceptFields(c)) { |
19 | O val = cget(c, field); |
20 | if (!val instanceof Concept) |
21 | cset(d, field, val); |
22 | else |
23 | cset(d, field, conceptGraphMap_impl(val/Concept, f, seen)); |
24 | } |
25 | ret d; |
26 | } |
Began life as a copy of #1005466
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: | #1005477 |
Snippet name: | conceptGraphMap - apply function to every concept in a concept graph |
Eternal ID of this version: | #1005477/1 |
Text MD5: | 0d7466eea53ada6206d5473bd2c554a2 |
Author: | stefan |
Category: | javax / concepts |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-11-20 19:53:37 |
Source code size: | 647 bytes / 26 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 550 / 553 |
Referenced in: | [show references] |