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

14
LINES

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

JavaX fragment (include)

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;
}

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   

Travelled to 10 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

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/8
Text MD5: 934f9c0a7c0330ca792600cd4f856d86
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-09 17:57:43
Source code size: 308 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 310 / 290
Version history: 7 change(s)
Referenced in: [show references]