Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created August 5, 2017 16:42
Show Gist options
  • Save beckyconning/63b7ba8291d28d204e2e349a3cbca2e7 to your computer and use it in GitHub Desktop.
Save beckyconning/63b7ba8291d28d204e2e349a3cbca2e7 to your computer and use it in GitHub Desktop.
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