Last active
August 29, 2015 13:56
-
-
Save agazso/8813306 to your computer and use it in GitHub Desktop.
replaceString
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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