Logo

Programming-Idioms

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

Idiom #254 Replace value in list

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

replaced = map (\e -> if e == "foo" then "bar" else e) x

Variables are not mutable, so we cannot assign it back to x.
(replace {"foo" "bar"} x)

New implementation...