-
-
Save beckyconning/e74682e7a1f9a137ba464a178eee0cee 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 Codewars.Kata.Dubstep where | |
import Prelude | |
import Data.List (unwords) | |
import Text.Parsec (many1, manyTill, try, anyChar, string, parse, many, skipMany, (<|>)) | |
-- unwords . filter (not . null) . splitOn "WUB" | |
-- The above is clearly the stronger solution however parser combinators are cool. | |
songDecoder :: String -> String | |
songDecoder = | |
either show unwords . parse song "" | |
song = | |
(skipMany $ try seperator) *> (many $ try stringFollowedBySeperator <|> nonEmptyString) | |
stringFollowedBySeperator = | |
manyTill anyChar (many1 $ try seperator) | |
nonEmptyString = | |
many1 anyChar | |
seperator = | |
string "WUB" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment