Safe Haskell | Safe-Inferred |
---|
NOTE: This module is preliminary and may change at a future date.
This module is intended to help converting a list of tags into a tree of tags.
Documentation
tagTree :: Eq str => [Tag str] -> [TagTree str]Source
Convert a list of tags into a tree. This version is not lazy at all, that is saved for version 2.
flattenTree :: [TagTree str] -> [Tag str]Source
transformTree :: (TagTree str -> [TagTree str]) -> [TagTree str] -> [TagTree str]Source
This operation is based on the Uniplate transform
function. Given a
list of trees, it applies the function to every tree in a bottom-up
manner. This operation is useful for manipulating a tree - for example
to make all tag names upper case:
upperCase = transformTree f where f (TagBranch name atts inner) = [TagBranch (map toUpper name) atts inner] f x = [x]
universeTree :: [TagTree str] -> [TagTree str]Source
This operation is based on the Uniplate universe
function. Given a
list of trees, it returns those trees, and all the children trees at
any level. For example:
universeTree [TagBranch "a" [("href","url")] [TagBranch "b" [] [TagLeaf (TagText "text")]]] == [TagBranch "a" [("href","url")] [TagBranch "b" [] [TagLeaf (TagText "text")]]] ,TagBranch "b" [] [TagLeaf (TagText "text")]]
This operation is particularly useful for queries. To collect all "a"
tags in a tree, simply do:
[x | x@(TagBranch "a" _ _) <- universeTree tree]