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

28
LINES

< > BotCompany Repo | #1024857 // roundRobinCombinedIterator

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

Libraryless. Click here for Pure Java version (2024L/13K).

static <A> ItIt<A> roundRobinCombinedIterator(Iterator<A>... iterators) {
  ret roundRobinCombinedIterator(wrapAsList(iterators));
}

static <A> ItIt<A> roundRobinCombinedIterator(Cl<? extends Iterator<A>> iterators) {
  if (empty(iterators)) ret emptyItIt();
  class Robin implements IF0 {
    L<? extends Iterator<A>> activeIterators = cloneList(iterators);
    int i;
    
    public O get() {
      while licensed {
        Iterator<A> it = activeIterators.get(i);
        if (!it.hasNext()) { 
          activeIterators.remove(i);
          if (empty(activeIterators)) break;
          i %= l(activeIterators);
        } else {
          i = (i+1) % l(activeIterators);
          ret it.next();
        }
      }
      ret endMarker();
    }
  }
  
  ret iff(new Robin);
}

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: #1024857
Snippet name: roundRobinCombinedIterator
Eternal ID of this version: #1024857/9
Text MD5: ffa0cc33493e610b7e5ee3b5d19064cb
Transpilation MD5: 798f80a9b0c7c0d1bc23b24fa64a5202
Author: stefan
Category: javax / chess ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-29 13:08:21
Source code size: 804 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 195 / 302
Version history: 8 change(s)
Referenced in: [show references]