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

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

static <A> L<A> replace(A a, A b, L<A> l) {
  ret replace(l, a, 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   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pzhvpgtvlbxg, 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/9
Text MD5: 7cee1207add47eecb0f9149d34e6941e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-29 14:40:50
Source code size: 383 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 389 / 381
Version history: 8 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1007775 & http://1007775.tinybrain.de