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

17
LINES

< > BotCompany Repo | #1006143 // splitAtListElement_multi - split list at (possibly repeating) occurrences of a splitter element

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

Libraryless. Click here for Pure Java version (2153L/14K).

1  
// returns empty first and empty last
2  
static <A> LL<A> splitAtListElement_multi(L<A> l, A splitter) {
3  
  l = unnull(l);
4  
  new LL<A> parts;
5  
  int i = 0;
6  
  while true {
7  
    int j = indexOf(l, splitter, i);
8  
    if (j < 0) {
9  
      parts.add(subList(l, i));
10  
      break;
11  
    }
12  
    parts.add(subList(l, i, j));
13  
    i = j+1;
14  
    while (i < l(l) && eq(l.get(i), splitter)) ++i;
15  
  }
16  
  ret parts;
17  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006143
Snippet name: splitAtListElement_multi - split list at (possibly repeating) occurrences of a splitter element
Eternal ID of this version: #1006143/3
Text MD5: cace7ba55ff6d2b88523d99b2d719a62
Transpilation MD5: e3b0ae722ccb2d90b1bef5169b7721a8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-13 17:49:38
Source code size: 403 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 549 / 630
Version history: 2 change(s)
Referenced in: [show references]