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

37
LINES

< > BotCompany Repo | #1018135 - nestedIterator

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

Libraryless. Click here for Pure Java version (2327L/15K).

// TODO: clean up these type signatures?

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

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

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

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

download  show line numbers  debug dex   

Travelled to 9 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1018135
Snippet name: nestedIterator
Eternal ID of this version: #1018135/12
Text MD5: e83ff879c2f6fb624493a4a5c72b4902
Transpilation MD5: be49045e02abec29d9f3e05caa2f201b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-26 14:15:06
Source code size: 1159 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 197 / 227
Version history: 11 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1018135 & http://1018135.tinybrain.de