Libraryless. Click here for Pure Java version (2223L/14K).
1 | // requires ugly casting when used (O -> A) |
2 | static O iteratorFromFunction_endMarker = new O; |
3 | |
4 | // f: func -> A | endMarker |
5 | static <A> IterableIterator<A> iteratorFromFunction_withEndMarker(fO f) { |
6 | class IFF extends IterableIterator<A> { |
7 | A a; |
8 | bool have, done; |
9 | |
10 | public bool hasNext() { |
11 | getNext(); |
12 | ret !done; |
13 | } |
14 | |
15 | public A next() { |
16 | getNext(); |
17 | if (done) fail(); |
18 | A _a = a; |
19 | a = null; |
20 | have = false; |
21 | ret _a; |
22 | } |
23 | |
24 | void getNext() { |
25 | if (done || have) ret; |
26 | O o = callF(f); |
27 | if (o == iteratorFromFunction_endMarker) |
28 | ret with done = true; |
29 | a = (A) o; |
30 | set have; |
31 | } |
32 | }; |
33 | ret new IFF; |
34 | } |
35 | |
36 | // optimized version for F0 argument; TODO: do same for IF0 |
37 | static <A> IterableIterator<A> iteratorFromFunction_withEndMarker(final F0 f) { |
38 | ret iteratorFromFunction_withEndMarker_f0(f); |
39 | } |
Began life as a copy of #1006726
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1012670 |
Snippet name: | iteratorFromFunction_withEndMarker |
Eternal ID of this version: | #1012670/10 |
Text MD5: | 079337852ad4d61ae8fa3b4d6eb9313d |
Transpilation MD5: | 1170bda7f0684a651bc5e269ea15291d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-10-28 11:47:45 |
Source code size: | 924 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 468 / 1050 |
Version history: | 9 change(s) |
Referenced in: | [show references] |