[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-cafe
Subject: Re: [Haskell-cafe] foldlWhile
From: "Serge D. Mechveliani" <mechvel () botik ! ru>
Date: 2004-11-22 6:41:47
Message-ID: 20041122094147.A345 () botik ! ru
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic