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

29
LINES

< > BotCompany Repo | #1026495 // transitiveHullIteratorOfFunction

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2290L/15K).

static <A> ItIt<A> mapLike transitiveHullIteratorOfFunction(IF1<A, Cl<A>> f, Set<A> initial, O... _) {
  Set<A> seen = similarEmptySet(initial);

  // Make pool of iterators
  final new LinkedList<Iterator<A>> pool;
  pool.add(iterator(initial));
  ret iteratorFromFunction(new F0<A> {
    int n = 0;
    
    public A get() {
      while ping (!empty(pool)) {
        Iterator<A> it = first(pool);
        if (!it.hasNext()) continue with removeFirst(pool);
        
        // Get entry and check if seen already
        A entry = it.next();
        if (!seen.add(entry)) continue;
  
        // found new entry - return and schedule for further analysis
        Collection<A> newStuff = cast callF(f, entry);
        if (nempty(newStuff))
          pool.add(iterator(newStuff));
        ++n;
        ret entry;
      }
      null;
    }
  });
}

Author comment

Began life as a copy of #1023767

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026495
Snippet name: transitiveHullIteratorOfFunction
Eternal ID of this version: #1026495/5
Text MD5: 276efbfd46dee58cc92a3c6450b0adf5
Transpilation MD5: 9c15747f0525f6b36b171e7c067fea31
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-06 23:53:05
Source code size: 875 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 190 / 284
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)