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

30
LINES

< > BotCompany Repo | #1020979 // iteratorFromFunction_withEndMarker_f0_autoCloseable

JavaX fragment (include)

1  
static <A> CloseableIterableIterator<A> iteratorFromFunction_withEndMarker_f0_autoCloseable(final F0<A> f, final AutoCloseable closeable) {
2  
  class IFF2 extends CloseableIterableIterator<A> {
3  
    A a;
4  
    bool done;
5  
    
6  
    public bool hasNext() {
7  
      getNext();
8  
      ret !done;
9  
    }
10  
    
11  
    public A next() {
12  
      getNext();
13  
      if (done) fail();
14  
      A _a = a;
15  
      a = null;
16  
      ret _a;
17  
    }
18  
    
19  
    void getNext() {
20  
      if (done || a != null) ret;
21  
      a = f.get();
22  
      done = a == endMarker();
23  
    }
24  
    
25  
    public void close() tex {
26  
      if (closeable != null) closeable.close();
27  
    }
28  
  };
29  
  ret new IFF2;
30  
}

Author comment

Began life as a copy of #1017244

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020979
Snippet name: iteratorFromFunction_withEndMarker_f0_autoCloseable
Eternal ID of this version: #1020979/1
Text MD5: edbb3c6196055c7aa462a1c44cf71d38
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-15 16:53:50
Source code size: 665 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 342 / 341
Referenced in: [show references]