30 Sep
2005
30 Sep
'05
2:48 p.m.
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))