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

26
LINES

< > BotCompany Repo | #1005477 // conceptGraphMap - apply function to every concept in a concept graph

JavaX fragment (include)

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

static Concept conceptGraphMap_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) {
    seen.put(c, d);
    ret d;
  }

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

Author comment

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: 548 / 551
Referenced in: [show references]