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

27
LINES

< > BotCompany Repo | #1018353 // splittableSteppable_forEach

JavaX fragment (include)

static <A> SplittableSteppable splittableSteppable_forEach(final Iterable<A> items, final VF1<A> f) {
  ret new SplittableSteppable {
    Iterator<A> it = iterator(items);
    public bool step() { // return false if done
      if (!it.hasNext()) false;
      callF(f, it.next());
      true;
    }
    
    // invalidates original steppable
    public L<Steppable> split(int n) {
      final Lock lock = lock();
      ret rep((Steppable) new Steppable {
        public bool step() {
          A a;
          {
            lock lock;
            if (!it.hasNext()) false;
            a = it.next();
          }
          callF(f, a);
          true;
        }
      }, n);
    }
  };
}

Author comment

Began life as a copy of #1018344

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018353
Snippet name: splittableSteppable_forEach
Eternal ID of this version: #1018353/3
Text MD5: a524a77e30042d019c06e88347ba3cfa
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-20 06:27:26
Source code size: 710 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 310 / 357
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)