[Haskell-cafe] An alternative break

Philip Weaver philip.weaver at gmail.com
Wed May 28 17:56:35 EDT 2008


On Wed, May 28, 2008 at 2:53 PM, Pieter Laeremans <pieter at laeremans.org> wrote:
> Hello,
>
> 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 ?
>
Your first two cases are redundant; you can eliminate the first one.
Other than that, it looks fine.

> thanks in advance,
>
> Pieter
>
> --
> Pieter Laeremans <pieter at laeremans.org>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list