Created
August 5, 2017 16:42
-
-
Save beckyconning/63b7ba8291d28d204e2e349a3cbca2e7 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.Functor (($>)) | |
import Data.Functor.Identity (Identity) | |
import Data.List (unwords, filter) | |
import Data.List.Split (splitOn) | |
import Data.Text (strip, pack, unpack) | |
import Text.Parsec | |
-- unwords . filter (not . null) . splitOn "WUB" | |
-- The above is clearly the stronger solution however I would like to | |
-- learn how to do this with parser combinators. | |
-- Currently if "WUB" is at the start and or end there will be a | |
-- leading / trailing space. | |
-- What parser would make (unpack . strip . pack) redundant? | |
songDecoder :: String -> String | |
songDecoder = | |
either show (unpack . strip . pack) | |
. parse | |
(many $ (many1 (try (string "WUB"))) $> ' ' <|> anyChar) | |
"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment