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

24
LINES

< > BotCompany Repo | #1028584 // itIt - convert to IterableIterator

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

Libraryless. Click here for Pure Java version (5133L/28K).

static <A> ItIt<A> itIt(ItIt<A> it) {
  if (it == null) ret emptyItIt();
  ret it;
}

static <A> ItIt<A> itIt(Iterator<A> it) {
  if (it == null) ret emptyItIt();
  if (it cast ItIt) ret it;
  ret new IterableIterator<A> {
    public bool hasNext() { ret it.hasNext(); }
    public A next() { ret it.next(); }
  };
}

static <A> ItIt<A> itIt(Iterable<A> l) {
  if (l == null) ret emptyItIt();
  if (l cast ItIt) ret l;
  Iterator<A> it = l.iterator();
  if (it cast ItIt) ret it;
  ret new IterableIterator<A> {
    public bool hasNext() { ret it.hasNext(); }
    public A next() { ret it.next(); }
  };
}

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: #1028584
Snippet name: itIt - convert to IterableIterator
Eternal ID of this version: #1028584/5
Text MD5: 9322ae334fc5572429e148e5fa55eb18
Transpilation MD5: 713ae1261bfc237e5ac52e78546028d0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-18 22:36:37
Source code size: 628 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 143 / 251
Version history: 4 change(s)
Referenced in: [show references]