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

19
LINES

< > BotCompany Repo | #1007775 // replace - replace an element in a list (modify original); also synonym for String.replace with null propagation

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

Libraryless. Click here for Pure Java version (2754L/16K).

1  
static <A> L<A> replace(L<A> l, A a, A b) {
2  
  for i over l:
3  
    if (eq(l.get(i), a))
4  
      l.set(i, b);
5  
  ret l;
6  
}
7  
8  
static <A> L<A> replace(A a, A b, L<A> l) {
9  
  ret replace(l, a, b);
10  
}
11  
12  
// replace all occurrences of a in s with b
13  
sS replace(S s, S a, S b) {
14  
  ret s == null ? null : a == null || b == null ? s : s.replace(a, b);
15  
}
16  
17  
sS replace(S s, char a, char b) {
18  
  ret s == null ? null : s.replace(a, b);
19  
}

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: #1007775
Snippet name: replace - replace an element in a list (modify original); also synonym for String.replace with null propagation
Eternal ID of this version: #1007775/10
Text MD5: 163981eb20a210c11174fad726c16284
Transpilation MD5: c622180eaa0e3cba02fba2d54ebe6074
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-05-25 21:01:40
Source code size: 428 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 638 / 679
Version history: 9 change(s)
Referenced in: [show references]