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

16
LINES

< > BotCompany Repo | #1008769 // findStreaks - find IntRanges of elements in a list where predicate is true

JavaX fragment (include)

static L<IntRange> findStreaks(L l, O pred) {
  new L<IntRange> out;
  int i = 0, n = l(l);
  while (i < n) {
    int j = i;
    while (j < n && isTrue(callF(pred, l.get(j)))) ++j;
    if (j > i)
      out.add(intRange(i, j));
    i = j+1;
  }
  ret out;
}

static L<IntRange> findStreaks(O pred, L l) {
  ret findStreaks(l, pred);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1008769
Snippet name: findStreaks - find IntRanges of elements in a list where predicate is true
Eternal ID of this version: #1008769/2
Text MD5: 4c3c2967e4d3a5bc6339077540cd1621
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-21 17:08:05
Source code size: 348 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 500 / 550
Version history: 1 change(s)
Referenced in: [show references]