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

22
LINES

< > BotCompany Repo | #1018118 // repeatedInputModificationsIterator

JavaX fragment (include)

static <A extends Iterator<S>> ItIt<S> repeatedInputModificationsIterator(S input, final F1<S, L<A>> makeIterators) {
  final HashSet<S> seen = lithashset(input);
  
  // Make pool of iterators
  final new LinkedList<Iterator<S>> pool;
  addAll(pool, callF(makeIterators, input));
  ret iteratorFromFunction(func -> S {
    while ping (!empty(pool)) {
      Iterator<S> it = first(pool);
      if (!it.hasNext()) continue with removeFirst(pool);
      
      // Get entry and check if seen already
      S entry = it.next();
      if (!seen.add(entry)) continue;

      // found new entry - return and schedule for further analysis
      addAll(pool, callF(makeIterators, entry));
      ret entry;
    }
    null;
  });
}

Author comment

Began life as a copy of #1018117

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018118
Snippet name: repeatedInputModificationsIterator
Eternal ID of this version: #1018118/9
Text MD5: b586b34ed0c469e464f21345817a3e65
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-02 17:10:44
Source code size: 742 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 410 / 453
Version history: 8 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1022233 - repeatFunctionReturningList_iterator