[Haskell-cafe] how to break foldl' ?
Henning Thielemann
lemming at henning-thielemann.de
Fri Sep 30 10:48:18 EDT 2005
On Fri, 30 Sep 2005, gary ng wrote:
> > This should work as expected:
> > takeWhile (<maxX) (scanl (+) 0 xs)
>
> Thanks. But how would I think about using scanl
> instead of foldl(or foldl') when I want is the sum,
> but not the progressive result. Once again show me
> that I need to throw away all imperative stuff.
No problem:
last (takeWhile (<maxX) (scanl (+) 0 xs))
Convinced?
The first sum which exceeds the limit could be computed with
head (dropWhile (<=maxX) (scanl (+) 0 xs))
More information about the Haskell-Cafe
mailing list