replace multimethod

Methods

replace(dst:Any, src:Any)
DISCOURAGED. Replace one object with another. dst and src must be of the same type.

Example

a = [1,2,3]
a.replace([4,5])
a  # [4,5]
replace(something:Eachable1, src:Any, dst:Any) Source: stdlib.ngs:525
Replace all occurrences of src with dst TODO: Return same type, not Arr

Parameters

somethingobject of any type that has each(something, callback) implemented

Returns

Arr

Example

["ssh", "IP", "w"].replace("IP", "10.0.0.100")  # ['ssh','10.0.0.100','w']
replace(s:Str, src:Str, dst:Str) Source: stdlib.ngs:3716
Replace all occurrences of src with dst in s
replace(s:Str, r:RegExp, mapper:Fun) Source: stdlib.ngs:5892
Replace all occurrences of r

Parameters

mapperFunction that will be called with one matching string at a time that provides the replacement

Returns

Str

Example

"x10ab20c30y".replace(/[0-9]+/, F(match_text) "[$match_text]")  # "x[10]ab[20]c[30]y"