Skip to content

Instantly share code, notes, and snippets.

@agazso
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save agazso/8813306 to your computer and use it in GitHub Desktop.

Select an option

Save agazso/8813306 to your computer and use it in GitHub Desktop.
replaceString
replaceString : String -> String -> String -> String
replaceString input from to = String.join to (String.split from input)
replaceString2 input from to = String.join to <| String.split from input
replaceString3 input from to = String.split from input |> String.join to
replaceString4 input from to = (String.join to . String.split from) input
replaceString5 input from to = String.join to . String.split from <| input
testReplace input from to output =
let tests = [replaceString, replaceString2, replaceString3, replaceString4, replaceString5]
in
foldr (&&) True <| map (\i -> i input from to == output) tests
test = testReplace "hello" "hello" "hi" "hi" &&
testReplace "hello" "l" "L" "heLLo" &&
testReplace "hello" "ll" "l" "helo" &&
testReplace "a/b/c" "/" "." "a.b.c"
main = asText test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment