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

17
LINES

< > BotCompany Repo | #1028583 // lazyListFromIterator

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

Libraryless. Click here for Pure Java version (45L/1K).

1  
static <A> L<A> lazyListFromIterator(Iterator<A> it) {
2  
  ret new RandomAccessAbstractList<A>() {
3  
    new L<A> list;
4  
    
5  
    public int size() { realizeFully(); ret list.size(); }
6  
    public A get(int i) { realizeUpTo(i); ret list.get(i); }
7  
    
8  
    void realizeUpTo(int i) {
9  
      while (i >= list.size() && it.hasNext())
10  
        list.add(it.next());
11  
    }
12  
    
13  
    void realizeFully() {
14  
      realizeUpTo(Int.MAX_VALUE);
15  
    }
16  
  };
17  
}

Author comment

Began life as a copy of #1028512

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: #1028583
Snippet name: lazyListFromIterator
Eternal ID of this version: #1028583/1
Text MD5: 2faf2e028c128fb73c2b219c20259236
Transpilation MD5: 90564697c44d1d890fe9105b8bce5d31
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-27 19:51:50
Source code size: 451 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 138 / 198
Referenced in: [show references]