Libraryless. Click here for Pure Java version (45L/1K).
static <A> L<A> lazyListFromIterator(Iterator<A> it) { ret new RandomAccessAbstractList<A>() { new L<A> list; public int size() { realizeFully(); ret list.size(); } public A get(int i) { realizeUpTo(i); ret list.get(i); } void realizeUpTo(int i) { while (i >= list.size() && it.hasNext()) list.add(it.next()); } void realizeFully() { realizeUpTo(Int.MAX_VALUE); } }; }
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: | 480 / 612 |
| Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |