Implement groupByLink in terms of foldr
This commit is contained in:
parent
cb4f4e7edc
commit
2c0766825e
|
@ -3858,13 +3858,13 @@ groupByLink :: (a -> a -> Bool) -> [a] -> [[a]]
|
||||||
groupByLink f list =
|
groupByLink f list =
|
||||||
case list of
|
case list of
|
||||||
[] -> []
|
[] -> []
|
||||||
(x:xs) -> g x [] xs
|
(x:xs) -> foldr c n xs x []
|
||||||
where
|
where
|
||||||
g current span (next:rest) =
|
c next rest current span =
|
||||||
if f current next
|
if f current next
|
||||||
then g next (current:span) rest
|
then rest next (current:span)
|
||||||
else (reverse $ current:span) : g next [] rest
|
else (reverse $ current:span) : rest next []
|
||||||
g current span [] = [reverse (current:span)]
|
n current span = [reverse (current:span)]
|
||||||
|
|
||||||
|
|
||||||
prop_checkBlatantRecursion1 = verify checkBlatantRecursion ":(){ :|:& };:"
|
prop_checkBlatantRecursion1 = verify checkBlatantRecursion ":(){ :|:& };:"
|
||||||
|
|
Loading…
Reference in New Issue