Add my (old) testsuite
[darcs-mirrors/vector.git] / testsuite / Testsuite / Utils / List.hs
1 module Testsuite.Utils.List ( accum, (//) )
2 where
3
4 import Data.List
5
6 accum :: (a -> b -> a) -> [a] -> [(Int,b)] -> [a]
7 accum f xs ps = go xs ps' 0
8 where
9 ps' = sortBy (\p q -> compare (fst p) (fst q)) ps
10
11 go (x:xs) ((i,y) : ps) j
12 | i == j = go (f x y : xs) ps j
13 go (x:xs) ps j = x : go xs ps (j+1)
14 go [] _ _ = []
15
16 (//) :: [a] -> [(Int, a)] -> [a]
17 xs // ps = go xs ps' 0
18 where
19 ps' = sortBy (\p q -> compare (fst p) (fst q)) ps
20
21 go (x:xs) ((i,y) : ps) j
22 | i == j = go (y:xs) ps j
23 go (x:xs) ps j = x : go xs ps (j+1)
24 go [] _ _ = []
25