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).

static <A> L<A> replace(L<A> l, A a, A b) {
  for i over l:
    if (eq(l.get(i), a))
      l.set(i, b);
  ret l;
}

static <A> L<A> replace(A a, A b, L<A> l) {
  ret replace(l, a, b);
}

// replace all occurrences of a in s with b
sS replace(S s, S a, S b) {
  ret s == null ? null : a == null || b == null ? s : s.replace(a, b);
}

sS replace(S s, char a, char b) {
  ret s == null ? null : s.replace(a, b);
}

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: 696 / 745
Version history: 9 change(s)
Referenced in: [show references]