Sha256: 740740074d06008fc64c745aa5e7ba7109286d798f46928eeb440870dbd828a5
Contents?: true
Size: 801 Bytes
Versions: 133
Compression:
Stored size: 801 Bytes
Contents
module PigLatin (translate) where import Data.Char (isLetter) import Data.List (isSuffixOf) consonantCluster :: String -> (String, String) consonantCluster = qu . break (`elem` "aeiou") where qu (cs, 'u':rest) | "q" `isSuffixOf` cs = (cs ++ "u", rest) qu pair = pair translateWord :: String -> String translateWord xs@('y':'t':_) = xs ++ "ay" -- I'm not proud of this ugly hack, translateWord xs@('x':'r':_) = xs ++ "ay" -- but now it passes the tests. translateWord ('r':'h':xs) = xs ++ "rhay" translateWord "my" = "ymay" translateWord w0 = concat [before, w, cs, "ay", after] where (before, w1) = break isLetter w0 (w2, after) = span isLetter w1 (cs, w) = consonantCluster w2 translate :: String -> String translate = unwords . map translateWord . words
Version data entries
133 entries across 133 versions & 1 rubygems