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).

1  
static <A> ItIt<A> itIt(ItIt<A> it) {
2  
  if (it == null) ret emptyItIt();
3  
  ret it;
4  
}
5  
6  
static <A> ItIt<A> itIt(Iterator<A> it) {
7  
  if (it == null) ret emptyItIt();
8  
  if (it cast ItIt) ret it;
9  
  ret new IterableIterator<A> {
10  
    public bool hasNext() { ret it.hasNext(); }
11  
    public A next() { ret it.next(); }
12  
  };
13  
}
14  
15  
static <A> ItIt<A> itIt(Iterable<A> l) {
16  
  if (l == null) ret emptyItIt();
17  
  if (l cast ItIt) ret l;
18  
  Iterator<A> it = l.iterator();
19  
  if (it cast ItIt) ret it;
20  
  ret new IterableIterator<A> {
21  
    public bool hasNext() { ret it.hasNext(); }
22  
    public A next() { ret it.next(); }
23  
  };
24  
}

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: 142 / 251
Version history: 4 change(s)
Referenced in: [show references]