Created
April 12, 2015 14:59
-
-
Save TheSeamau5/9f2f8d0fde0a3d631042 to your computer and use it in GitHub Desktop.
String Match On
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
matchOn : String -> String -> Maybe String | |
matchOn start string = | |
if startsWith start string | |
then | |
Just <| dropLeft (length start) string | |
else | |
Nothing |
The match
function for the DSL:
match : List (String, String -> a) -> (String -> a) -> String -> a
match list defaultMatch url = case list of
[] -> defaultMatch url
(str, matcher) :: ms ->
-- Test for empty string matcher (usually home)
if
str == ""
then
if
url == ""
then
matcher url
else
match ms defaultMatch url
else
case matchOn str url of
Just value -> matcher value
Nothing -> match ms defaultMatch url
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With a DSL too: