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: | 731 / 791 |
Version history: | 9 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1018666 - syncReplace - replace an element in a list (modify original), sync on list #1026538 - replace_multi #1028493 - insertBefore - insert a string before first occurrence of a substring #1031921 - replaceInClonedList #1032324 - replace_optimized - replace only when a and b are different |