在haskell中使用foldr拆分

时间:2015-08-26 01:59:13

标签: haskell

我需要使用split

编写一个函数foldr
split :: Eq a ⇒ a → [a] → [[ a ]]

示例:

split '/' ”hello/my/friends” ----> [”hello”,”my”,”friends”]

这是我尝试过的:

split :: Eq a ⇒ a → [a] → [[ a ]]
split str delim = let (start, end) = break (== delim) str
                in start : if null end then [] else groupBy (tail end) delim 

1 个答案:

答案 0 :(得分:4)

这样的事情应该有效:

split on = foldr (\c (x:xs) ->
    if c == on
    then []:x:xs
    else (c:x):xs
  ) [[]]

广义:

public void onStop() {
    super.onStop();
    // code where you tell the app to save the image
}

public void onDestroy() {
    super.onDestroy();
    // code where you tell the app to save the image
}