On Sat, Nov 20, 2004 at 12:47:58PM +0300, Serge D. Mechveliani wrote: > Is such a function familia to the Haskell users? > > 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.
Why not just foldlWhile f p a bs = takeWhile p $ foldl f a bs ? > More `generic' variant: > > foldlWhileJust :: (a -> b -> Maybe a) -> a -> [b] -> a > foldlWhileJust f a bs = case bs of > > [] -> a > b:bs' -> case f a b of Just a' -> foldlWhileJust f a' bs' > _ -> a I don't know a short way to rewrite this one yet. Peace, Dylan
signature.asc
Description: Digital signature
_______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe