From haskell-cafe Sat Nov 20 16:55:08 2004 From: Jorge Adriano Aires Date: Sat, 20 Nov 2004 16:55:08 +0000 To: haskell-cafe Subject: Re: [Haskell-cafe] foldlWhile Message-Id: <200411201655.08590.jadrian () mat ! uc ! pt> X-MARC-Message: https://marc.info/?l=haskell-cafe&m=120491986638590 (opss just noticed I did a reply-to) > > The following is closer to the original, but doesn't work when the whole > > list is folded (i.e., p always satisfied): > > foldlWhile f p a = head . dropWhile p . scanl f a > > Serge's version returns the last 'a' that satisfies 'p', while yours Not really. > returns the first 'a' that does not satisfy 'p'. This should be an > equivalent version: Yeap, just like his, foldlWhile :: (a -> b -> a) -> (a -> Bool) -> a -> [b] -> a foldlWhile f p a bs = (_, False) -> a It tests the accumulator with p, and returns it on "false". J.A.