Skip to content

Instantly share code, notes, and snippets.

@mmynsted

mmynsted/Main.hs Secret

Created October 18, 2020 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmynsted/bc2fc5c083c5d27ebfd5aab8bb8bc6c3 to your computer and use it in GitHub Desktop.
Save mmynsted/bc2fc5c083c5d27ebfd5aab8bb8bc6c3 to your computer and use it in GitHub Desktop.
{-# 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