Refactor wall zoning, remove streaming
This commit is contained in:
@@ -10,8 +10,13 @@ module ListHelp
|
||||
, foldPairs
|
||||
, loopPairs
|
||||
, slideWindow
|
||||
|
||||
, merge
|
||||
, mergeBy
|
||||
, mergeOn
|
||||
) where
|
||||
import Data.List
|
||||
import Data.Ord
|
||||
|
||||
loopPairs :: [a] -> [(a,a)]
|
||||
loopPairs (a:as) = snd $ foldr f (Just a,[]) (a:as)
|
||||
@@ -65,3 +70,18 @@ errorHead s [] = error s
|
||||
|
||||
slideWindow :: Int -> [a] -> [[a]]
|
||||
slideWindow n = foldr (zipWith (:)) (repeat []) . take n . tails
|
||||
|
||||
merge :: Ord a => [a] -> [a] -> [a]
|
||||
merge = mergeBy compare
|
||||
|
||||
mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
|
||||
mergeBy _ xs [] = xs
|
||||
mergeBy _ [] ys = ys
|
||||
mergeBy f (x:xs) (y:ys)
|
||||
| f x y /= GT = x : mergeBy f xs (y:ys)
|
||||
| otherwise = y : mergeBy f (x:xs) ys
|
||||
|
||||
mergeOn :: Ord b => (a -> b) -> [a] -> [a] -> [a]
|
||||
mergeOn f xs = map snd . mergeBy (comparing fst) (g xs) . g
|
||||
where
|
||||
g = map (\x -> let y = f x in y `seq` (y,x))
|
||||
|
||||
Reference in New Issue
Block a user