
To my question of
foldlWhile :: (a -> b -> a) -> (a -> Bool) -> a -> [b] -> a foldlWhile f p a bs = case (bs, p a) of ([], _ ) -> a (_, False) -> a (b:bs', _ ) -> foldlWhile f p (f a b) bs'
foldl does not seem to cover this.
Dylan Thurston wrote: On Nov 20, 2004
An alternative is
foldlWhile f p a bs = last $ takeWhile p $ scanl f a bs
Yes. Thank you. Inspecting Prelude, we find out that scanl expresses, mainly, the thing. ----------------- Serge Mechveliani mechvel@botik.ru

On Mon, Nov 22, 2004 at 09:41:47AM +0300, Serge D. Mechveliani wrote:
Yes. Thank you. Inspecting Prelude, we find out that scanl expresses, mainly, the thing.
Did you find a good replacement for the second function, foldWhileJust? Come to think of it, the way to do that would be to turn the accumulator to a function from Maybe a to Maybe a, like this: import Maybe(fromJust,isJust) foldWhileJust :: (a -> b -> Maybe a) -> a -> [b] -> a foldWhileJust f a = let f' :: Maybe a -> b -> Maybe a f' = maybe (const Nothing) f in fromJust . last . takeWhile isJust . scanl f' (Just a) Peace, Dylan
participants (2)
-
dpt@bostoncoop.net
-
Serge D. Mechveliani