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

45
LINES

< > BotCompany Repo | #1018135 - nestedIterator

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

Libraryless. Click here for Pure Java version (2662L/17K).

// 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 = 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   

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

No comments. add comment

Snippet ID: #1018135
Snippet name: nestedIterator
Eternal ID of this version: #1018135/16
Text MD5: e5918c19e0e1fab4cd4f55f7c87da4b6
Transpilation MD5: 73d031115a753acd3399b7446aa815fc
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-30 18:23:14
Source code size: 1514 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 268 / 339
Version history: 15 change(s)
Referenced in: [show references]

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