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

15
LINES

< > BotCompany Repo | #1021528 // splitAtLinePredicate - split at lines satisfying a predicate

JavaX fragment (include)

1  
// pred: func(S) -> bool
2  
static L<S> mapLike splitAtLinePredicate(O pred, S text) {
3  
  L<S> lines = toLines(text);
4  
  new L<S> l;
5  
  int i = 0;
6  
  while (i < l(lines)) {
7  
    int j = i;
8  
    while (j < l(lines) && !callPred(pred, lines.get(j)))
9  
      ++j;
10  
    if (j > i)
11  
      l.add(joinLines(lines.subList(i, j)));
12  
    i = j+1;
13  
  }
14  
  ret l;
15  
}

Author comment

Began life as a copy of #1003804

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1021528
Snippet name: splitAtLinePredicate - split at lines satisfying a predicate
Eternal ID of this version: #1021528/1
Text MD5: d834e746b085ebe17bf493f4af651097
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-17 14:49:47
Source code size: 351 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 292 / 305
Referenced in: [show references]