Split a character string based on change of character: Difference between revisions

Content added Content deleted
(→‎{{header|Haskell}}: Added a variant expressed in terms of `span`)
Line 1,252: Line 1,252:
charGroups :: String -> [String]
charGroups :: String -> [String]
charGroups [] = []
charGroups [] = []
charGroups (c : cs) = (c : xs) : charGroups ys
charGroups (c : cs) =
let (xs, ys) = span (c ==) cs
where
(xs, ys) = span (c ==) cs
in (c : xs) : charGroups ys


main :: IO ()
main :: IO ()