Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added merge function for future purposes.

  • Loading branch information...
commit 3ba2611ffd3af445f386bfd8bfb434fc3ded275e 1 parent 1545d18
@sebastiaanvisser sebastiaanvisser authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/Text/XmlHtml/Arrow.hs
View
16 src/Text/XmlHtml/Arrow.hs
@@ -110,6 +110,22 @@ data Z a = Z
instance Show a => Show (Z a) where
show (Z f _ _ _) = "(Z) " ++ show f
+-- | Merge a series of ordered lists into a single list. This defintion is a
+-- direct copied from the standard Haskell Data.List.sortBy.
+
+mergeNodeSet :: (a -> a -> Ordering) -> [[a]] -> [a]
+mergeNodeSet cmp = mergeAll
+ where mergeAll [] = []
+ mergeAll [x] = x
+ mergeAll xs = mergeAll (mergePairs xs)
+ mergePairs (a:b:xs) = merge a b : mergePairs xs
+ mergePairs xs = xs
+ merge as@(a:as')
+ bs@(b:bs')
+ | a `cmp` b == GT = b:merge as bs'
+ | otherwise = a:merge as' bs
+ merge [] bs = bs
+ merge as [] = as
mkZ :: Arrow (~>) => a ~> Z a
mkZ = arr (\a -> Z a Nothing [] [])
Please sign in to comment.
Something went wrong with that request. Please try again.