Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1005480 // conceptGraphMap_aggressive - apply function to every concept in a concept graph, repeatedly calling the function

JavaX fragment (include)

// f : Concept -> Concept
static Concept conceptGraphMap_aggressive(Concept c, O f) {
  ret conceptGraphMap_aggressive_impl(c, f, new IdentityHashMap);
}

static Concept conceptGraphMap_aggressive_impl(Concept c, O f, IdentityHashMap<Concept, Concept> seen) {
  if (seen.containsKey(c))
    ret seen.get(c);
  Concept d = cast callF(f, c);
  if (d != c) {
    Concept last = c;
    while (d != last && d != null) {
      last = d;
      d = (Concept) callF(f, d);
    }
  }
  
  if (d == null) {
    seen.put(c, null);
    null;
  }

  Concept e = cnew(d.getClass());
  seen.put(c, e);
  
  for (S field : conceptFields(d)) {
    O val = cget(d, field);
    if (!val instanceof Concept)
      cset(e, field, val);
    else
      cset(e, field, conceptGraphMap_aggressive_impl(val/Concept, f, seen));
  }
  ret e;
}

Author comment

Began life as a copy of #1005477

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: #1005480
Snippet name: conceptGraphMap_aggressive - apply function to every concept in a concept graph, repeatedly calling the function
Eternal ID of this version: #1005480/1
Text MD5: 1fa240fcf5d246b5b6a0d439a14975df
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 20:34:39
Source code size: 849 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 484 / 495
Referenced in: [show references]