Skip to content

Instantly share code, notes, and snippets.

@spion
Last active August 29, 2015 14:03
Show Gist options
  • Save spion/2872e5e793315b1ee1e5 to your computer and use it in GitHub Desktop.
Save spion/2872e5e793315b1ee1e5 to your computer and use it in GitHub Desktop.
import qualified Data.Map.Strict as M
data Node = Text String | Element (M.Map String AttributeValue)
data AttributeValue = Value String | Content [Node]
extractContent :: Node -> [String]
extractContent (Text s) = [s]
extractContent (Element e) =
case M.lookup "content" e of
Just (Content list) -> list >>= extractContent
_ -> []
import qualified Data.Map.Strict as M
type Attributes = M.Map String String
data Node = Text String | Element Attributes [Node]
extractContent :: Node -> [String]
extractContent (Text s) = [s]
extractContent (Element _ nodes) = nodes >>= extractContent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment