Created
February 6, 2013 11:41
-
-
Save yuroyoro/4722086 to your computer and use it in GitHub Desktop.
Haskellの練習でLTSVパースするヤツ
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
| import qualified Data.Map as M | |
| import Data.List.Split | |
| type Field = (String,String) | |
| type Fields = M.Map String String | |
| main = do cs <- getContents | |
| mapM_ showTree' $ parse cs | |
| showTree' :: Fields -> IO() | |
| showTree' = putStr . M.showTree | |
| parse :: String -> [Fields] | |
| parse = map parseLTSV . lines | |
| parseLTSV :: String -> Fields | |
| parseLTSV = M.fromList . map splitField . splitOn "\t" | |
| splitField :: String-> Field | |
| splitField = dropEqual . break (==':') | |
| where dropEqual (a, ':':b) = (a,b) | |
| dropEqual (a,b) = (a,b) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment