@@ 1,7 1,7 @@
-- | Abstracts away tree traversals.
-- Mostly used by callers including (soon) XML Conduit Stylist,
-- but also used internally for generating counter text.
-module Data.CSS.StyleTree(StyleTree(..), treeOrder, treeOrder', Path, treeMap) where
+module Data.CSS.StyleTree(StyleTree(..), treeOrder, treeOrder', Path, treeMap, treeFlatten) where
data StyleTree p = StyleTree {
style :: p,
@@ 26,3 26,10 @@ treeOrder' _ _ _ [] _ = error "Invalid path during tree traversal!"
treeMap :: (p -> p') -> StyleTree p -> StyleTree p'
treeMap cb = treeOrder (\_ _ _ p -> ((), cb p)) ()
+
+treeFlatten :: StyleTree p -> [p]
+treeFlatten = treeFlatten' . children
+treeFlatten' :: [StyleTree p] -> [p]
+treeFlatten' (StyleTree p []:ps) = p : treeFlatten' ps
+treeFlatten' (StyleTree _ childs:sibs) = treeFlatten' childs ++ treeFlatten' sibs
+treeFlatten' [] = []