创建连续字符列表?

时间:2016-10-28 18:46:12

标签: haskell

基本问题,但我似乎无法找到有效的解决方案。

我有以下[Char]:

"cdea...x...pwpee"

我希望将其转换为[[Char]]:

[[cdea], [x], [pwpee]] --create a lists of contiguous a's

我目前的解决方案只设法得到前三个:

myFunction :: [Char] -> [[Char]]
myFunction (x : xs)
  | x == 'a' = [x] : myFunction xs
  | otherwise = [] 

输出:

[c,d,e,a]

是否有明显的解决方案来获得我想要的结果?

0 个答案:

没有答案
相关问题