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

69
LINES

< > BotCompany Repo | #1018135 // nestedIterator

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

Libraryless. Click here for Pure Java version (7656L/43K).

1  
// TODO: clean up these type signatures?
2  
3  
static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(Iterable<A> c, final F1<A, C> makeInnerIterator) {
4  
  ret nestedIterator(iterator(c), makeInnerIterator);
5  
}
6  
7  
static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(Iterable<A> c, IF1<A, C> makeInnerIterator) {
8  
  ret nestedIterator(iterator(c), makeInnerIterator);
9  
}
10  
11  
static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(ItIt<A> c, IF1<A, C> makeInnerIterator) {
12  
  ret nestedIterator((Iterator<A>) c, makeInnerIterator);
13  
}
14  
15  
static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(Iterator<A> it1, IF1<A, C> makeInnerIterator) {
16  
  if (it1 == null || !it1.hasNext()) ret emptyItIt();
17  
  ret iff(new F0 {
18  
    A a;
19  
    Iterator<B> innerIterator;
20  
    
21  
    { nextOuter(); }
22  
    
23  
    void nextOuter {
24  
      a = it1.next();
25  
      innerIterator = makeInnerIterator.get(a);
26  
    }
27  
    
28  
    public O get() {
29  
      while true { ping();
30  
        if (innerIterator != null && innerIterator.hasNext())
31  
          ret innerIterator.next();
32  
        if (!it1.hasNext()) ret endMarker();
33  
        nextOuter();
34  
      }
35  
    }
36  
  });
37  
}
38  
39  
static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(final Iterator<A> it1, F1<A, C> makeInnerIterator) {
40  
  if (it1 == null || !it1.hasNext()) ret emptyItIt();
41  
  ret iff(new F0 {
42  
    A a;
43  
    Iterator<B> innerIterator;
44  
    
45  
    { nextOuter(); }
46  
    
47  
    void nextOuter {
48  
      a = it1.next();
49  
      innerIterator = makeInnerIterator.get(a);
50  
    }
51  
    
52  
    public O get() {
53  
      while true { ping();
54  
        if (innerIterator != null && innerIterator.hasNext())
55  
          ret innerIterator.next();
56  
        if (!it1.hasNext()) ret endMarker();
57  
        nextOuter();
58  
      }
59  
    }
60  
  });
61  
}
62  
63  
static <A, B, C extends Iterator<B>> ItIt<B> lambdaMapLike nestedIterator(IF1<A, C> makeInnerIterator, Iterator<A> it1) {
64  
  ret nestedIterator(it1, makeInnerIterator);
65  
}
66  
67  
static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(IF1<A, C> makeInnerIterator, Cl<A> l) {
68  
  ret nestedIterator(l, makeInnerIterator);
69  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1018135
Snippet name: nestedIterator
Eternal ID of this version: #1018135/20
Text MD5: df1a47e18008bb60fb1515cf722c3408
Transpilation MD5: 8dc5e6d8e4ece820a7411f40c81fad87
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-30 01:29:22
Source code size: 2103 bytes / 69 lines
Pitched / IR pitched: No / No
Views / Downloads: 535 / 741
Version history: 19 change(s)
Referenced in: [show references]