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).

// TODO: clean up these type signatures?

static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(Iterable<A> c, final F1<A, C> makeInnerIterator) {
  ret nestedIterator(iterator(c), makeInnerIterator);
}

static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(Iterable<A> c, IF1<A, C> makeInnerIterator) {
  ret nestedIterator(iterator(c), makeInnerIterator);
}

static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(ItIt<A> c, IF1<A, C> makeInnerIterator) {
  ret nestedIterator((Iterator<A>) c, makeInnerIterator);
}

static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(Iterator<A> it1, IF1<A, C> makeInnerIterator) {
  if (it1 == null || !it1.hasNext()) ret emptyItIt();
  ret iff(new F0 {
    A a;
    Iterator<B> innerIterator;
    
    { nextOuter(); }
    
    void nextOuter {
      a = it1.next();
      innerIterator = makeInnerIterator.get(a);
    }
    
    public O get() {
      while true { ping();
        if (innerIterator != null && innerIterator.hasNext())
          ret innerIterator.next();
        if (!it1.hasNext()) ret endMarker();
        nextOuter();
      }
    }
  });
}

static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(final Iterator<A> it1, F1<A, C> makeInnerIterator) {
  if (it1 == null || !it1.hasNext()) ret emptyItIt();
  ret iff(new F0 {
    A a;
    Iterator<B> innerIterator;
    
    { nextOuter(); }
    
    void nextOuter {
      a = it1.next();
      innerIterator = makeInnerIterator.get(a);
    }
    
    public O get() {
      while true { ping();
        if (innerIterator != null && innerIterator.hasNext())
          ret innerIterator.next();
        if (!it1.hasNext()) ret endMarker();
        nextOuter();
      }
    }
  });
}

static <A, B, C extends Iterator<B>> ItIt<B> lambdaMapLike nestedIterator(IF1<A, C> makeInnerIterator, Iterator<A> it1) {
  ret nestedIterator(it1, makeInnerIterator);
}

static <A, B, C extends Iterator<B>> ItIt<B> nestedIterator(IF1<A, C> makeInnerIterator, Cl<A> l) {
  ret nestedIterator(l, makeInnerIterator);
}

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: 536 / 742
Version history: 19 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)