-
-
Save mmynsted/bc2fc5c083c5d27ebfd5aab8bb8bc6c3 to your computer and use it in GitHub Desktop.
This file contains 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 #-} | |
_ | |
import qualified Data.ByteString.Lazy as BL | |
import Data.Csv | |
import qualified Data.Vector as V | |
~ import Data.Char | |
data RedirectMap= RedirectMap | |
{ badUrl :: String | |
, goodUrl :: String | |
} | |
myOptions :: DecodeOptions | |
myOptions = defaultDecodeOptions { decDelimiter = fromIntegral (ord '\t') } | |
instance FromNamedRecord RedirectMap where | |
parseNamedRecord r = RedirectMap <$> r .: "badUrl" <*> r .: "goodUrl" | |
main :: IO () | |
main = do | |
~ xs <- readInUrls | |
~ print $ show xs | |
~ | |
~ readInUrls = do | |
~ csvData <- BL.readFile "test.tsv" | |
~ case decodeByNameWith myOptions csvData of | |
~ Left err -> pure ([] :: [(String, String)]) | |
~ Right (_, v) -> pure . V.toList $ V.map redirectMapToPair v | |
~ | |
~ | |
~ redirectMapToPair :: RedirectMap -> (String, String) | |
~_redirectMapToPair (RedirectMap bad good) = (,) bad good |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment