[Haskell-cafe] ANNOUNCE: The Monad.Reader - Issue 6

David House dmhouse at gmail.com
Thu Feb 1 03:27:07 EST 2007


On 31/01/07, David House <dmhouse at gmail.com> wrote:
> dw :: (a -> Bool) -> [a] -> [a]
> dw p = reverse . fst . foldl comb ([],False)
>  where comb (xs,done) x | done      = (x:xs, True)
>                         | p x       = (xs, False)
>                         | otherwise = (x:xs, True)

I forgot to mention: I used foldl because it was neater, but you can
easily convert it to use foldr by reversing the list first and
swapping the arguments to comb.

-- 
-David House, dmhouse at gmail.com


More information about the Haskell-Cafe mailing list