
On 2004.04.22 15:02, I wrote:
splitAll :: (Real a) => a -> [a] -> [[a]] splitAll = unfoldr . split where split _ [] = Nothing split n xs = let (ys,zs) = break ((> n) . snd) (zip xs (scanl1 (+) xs)) in Just (map fst ys, map fst zs)
a slight improvement: splitAll :: (Real a) => a -> [a] -> [[a]] splitAll n = unfoldr split where split [] = Nothing split xs = let (ys,zs) = break ((> n) . snd) (zip xs (scanl1 (+) xs)) in Just (map fst ys, map fst zs) But in fact, I think you can do better still by not holding n constant but using a higher threshold on each split and not projecting out the values of the second component, thus only zipping the whole list once. --Joe Joseph H. Fasel, Ph.D. email: jhf@lanl.gov Systems Planning and Analysis phone: +1 505 667 7158 University of California fax: +1 505 667 2960 Los Alamos National Laboratory post: D-2 MS F609; Los Alamos, NM 87545