Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #254 Replace value in list

Replace all occurrences of "foo" with "bar" in the string list x

(replace {"foo" "bar"} x)
replaced = map (\e -> if e == "foo" then "bar" else e) x
x = x.map(e => e === 'foo' ? 'bar' : e);
classes
for i := 0 to x.count - 1 do
  if x[i] = 'foo' then
    x[i] := 'bar';
x = ["bar" if v=="foo" else v for v in x]
for i, v in enumerate(x):
  if v == "foo":
    x[i] = "bar"
x.map!{|el| el == "foo" ? "bar" : el}

Do you know the best way to do this in your language ?
New implementation...