Last active
August 29, 2015 14:21
-
-
Save PkmX/bfa02ccc668cf121e0d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings, TupleSections #-} | |
import Control.Monad | |
import Control.Lens | |
import Data.Function | |
import Data.List | |
import Data.Ord | |
import qualified Data.Text.Lazy.IO as TL | |
import qualified Text.Taggy.Lens as T | |
main :: IO () | |
main = do | |
allElements <- TL.getContents <&> toListOf (T.html . T.elements . T.allNamed (only "body") . to universe . traverse) | |
let result = sortBy (comparing $ Down . length . snd) [ (e, xs) | e <- allElements, xs <- groupByElement (children e) ] | |
forM_ result $ \(e, xs) -> print (T.eltName e, map T.eltName xs) | |
where groupByElement = groupBy ((==) `on` view T.name) . sortBy (comparing $ view T.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment