Last active
May 25, 2020 13:03
-
-
Save specdrake/2560f09f212982d4f27726e4b825d998 to your computer and use it in GitHub Desktop.
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
module String where | |
import Data.List | |
notThe :: String -> Maybe String | |
notThe = wrapper . unwords . filter (\x -> x /="the" && x /="The") . words | |
notThe' :: String -> String | |
notThe' l@(x0:x1:x2:x3:x4) = case (x0) of | |
' ' -> case (x4) of | |
(' ':_) -> case (x1:x2:x3:[]) of | |
"the" -> notThe' x4 | |
"The" -> notThe' x4 | |
_ -> x0 : (notThe' $ tail l) | |
[] -> case (x1:x2:x3:[]) of | |
"the" -> [] | |
"The" -> [] | |
_ -> (x1:x2:x3:[]) | |
_ -> x0 : (notThe' $ tail l) | |
_ -> x0 : (notThe' $ tail l) | |
notThe' l@(x0:x1:x2:[]) = l | |
notThe' l@(x0:x1:[]) = l | |
notThe' l@(x0:[]) = l | |
notThe' "" = "" | |
wrapper :: String -> Maybe String | |
wrapper str = case str of | |
"" -> Nothing | |
x -> Just x | |
notThe'' :: String -> Maybe String | |
-- start case | |
notThe'' l@(x:[]) = Just l | |
notThe'' l@(x0:x1:[]) = Just l | |
notThe'' l@(x0:x1:x2:[]) = case l of | |
"The" -> Nothing | |
"the" -> Nothing | |
_ -> Just l | |
notThe'' l@(x0:x1:x2:x3:[]) = case x3 of | |
' ' -> case init l of | |
"The" -> Just $ x3:[] | |
"the" -> Just $ x3:[] | |
_ -> Just l | |
-- for middle and end case | |
notThe'' lst = wrapper . notThe' $ lst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment