[Haskell-cafe] An alternative break

Pieter Laeremans pieter at laeremans.org
Wed May 28 17:53:31 EDT 2008


I need a break function that splits the list one element further than
the ordinary break.
This is the simplest solution I could imagine:

breakI :: (a -> Bool) -> [a] -> ([a], [a])
breakI p s = case break p s of
               ([], []) -> ([], [])
               (x, []) -> (x, [])
               (x,  l)  ->  (x ++ [head l], tail l )

Is there a better way to write this ?

thanks in advance,


Pieter Laeremans <pieter at laeremans.org>

More information about the Haskell-Cafe mailing list